Skip to content

Commit 0fa8b65

Browse files
author
Kelven Yang
committed
bug 10656: check OutOfMemoryError in critical path, fix run.sh to let it be able to monitor process termination
1 parent 506ca6c commit 0fa8b65

8 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎console-proxy/scripts/run.sh‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
while true
2828
do
29-
./_run.sh "$@"
29+
./_run.sh "$@" &
30+
wait
3031
ex=$?
3132
if [ $ex -eq 0 ] || [ $ex -eq 1 ] || [ $ex -eq 66 ] || [ $ex -gt 128 ]; then
3233
# permanent errors
33-
sleep 160
34+
sleep 5
3435
elif [ $ex -eq 143 ]; then
3536
# service cloud stop causes exit with 143
3637
exit $ex
3738
fi
38-
sleep 20
39+
sleep 5
3940
done

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ else if(start > 0)
285285
s_logger.warn("Exception in handle client event bag: " + data + ", ", e);
286286
} catch(Exception e) {
287287
s_logger.warn("Exception in handle client event bag: " + data + ", ", e);
288+
} catch(OutOfMemoryError e) {
289+
s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
290+
System.exit(1);
288291
}
289292
}
290293
}

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyCmdHandler.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public void handle(HttpExchange t) throws IOException {
4545
OutputStream os = t.getResponseBody();
4646
os.write(response.getBytes());
4747
os.close();
48+
} catch(OutOfMemoryError e) {
49+
s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
50+
System.exit(1);
4851
} catch (Throwable e) {
4952
s_logger.error(e.toString(), e);
5053
} finally {

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyMonitor.java‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828

2929
import com.cloud.console.Logger;
3030

31+
//
32+
// This class is not currently in use, was planning to add a simulated embedded VNC server and monitor console proxy health by
33+
// creating a fake client within the class, but this looks over-complicated and it may not be a reliable approach
34+
//
35+
// I switched to a simpler solution to monitor only unrecoverable exceptions, under these cases, console proxy process will exit
36+
// itself and the shell script will re-launch console proxy
37+
//
3138
public class ConsoleProxyMonitor {
3239
private static final Logger s_logger = Logger.getLogger(ConsoleProxyMonitor.class);
3340

@@ -56,8 +63,8 @@ private void run() {
5663
Runtime.getRuntime().addShutdownHook(new Thread() {
5764
@Override
5865
public void run() {
59-
onShutdown();
6066
_quit = true;
67+
onShutdown();
6168
}
6269
});
6370

@@ -73,10 +80,19 @@ public void run() {
7380
System.exit(1);
7481
}
7582

76-
try {
77-
_process.waitFor();
78-
} catch (InterruptedException e) {
79-
// TODO
83+
boolean waitSucceeded = false;
84+
int exitCode = 0;
85+
while(!waitSucceeded) {
86+
try {
87+
exitCode = _process.waitFor();
88+
waitSucceeded = true;
89+
90+
if(s_logger.isInfoEnabled())
91+
s_logger.info("Console proxy process exits with code: " + exitCode);
92+
} catch (InterruptedException e) {
93+
if(s_logger.isInfoEnabled())
94+
s_logger.info("InterruptedException while waiting for termination of console proxy, will retry");
95+
}
8096
}
8197
}
8298
}
@@ -97,6 +113,11 @@ private String getLaunchCommandLine() {
97113
}
98114

99115
private void onShutdown() {
116+
if(_process != null) {
117+
if(s_logger.isInfoEnabled())
118+
s_logger.info("Console proxy monitor shuts dwon, terminate console proxy process");
119+
_process.destroy();
120+
}
100121
}
101122

102123
private static void configLog4j() {

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public void handle(HttpExchange t) throws IOException {
6161
OutputStream os = t.getResponseBody();
6262
os.write(response.getBytes());
6363
os.close();
64+
} catch(OutOfMemoryError e) {
65+
s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
66+
System.exit(1);
6467
} catch (Throwable e) {
6568
s_logger.error("Unexpected exception while handing thumbnail request, ", e);
6669

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyViewer.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ public void run() {
217217
status = STATUS_AUTHENTICATION_FAILURE;
218218
String msg = e.getMessage();
219219
s_logger.warn("Authentication exception, msg: " + msg + "sid: " + this.passwordParam);
220+
} catch(OutOfMemoryError e) {
221+
s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
222+
System.exit(1);
220223
} catch (Exception e) {
221224
status = STATUS_ERROR;
222225
s_logger.error("Unexpected exception ", e);

‎console/src/com/cloud/console/ConsoleCanvas.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ public void processNormalProtocol() throws Exception {
358358

359359
// rethrow the exception;
360360
throw e;
361-
}
361+
} catch(OutOfMemoryError e) {
362+
s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
363+
System.exit(1);
364+
}
362365
}
363366

364367
private void processNormalProtocol2() throws Exception {

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,10 @@ public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
14571457
s_logger.error("Unable to send http handling startup command to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
14581458
} catch (OperationTimedoutException e) {
14591459
s_logger.error("Unable to send http handling startup command(time out) to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
1460-
} catch (Exception e) {
1460+
} catch(OutOfMemoryError e) {
1461+
s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
1462+
System.exit(1);
1463+
} catch (Exception e) {
14611464
s_logger.error("Unexpected exception when sending http handling startup command(time out) to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
14621465
}
14631466
}

0 commit comments

Comments
 (0)