Skip to content

Commit e78bb1d

Browse files
committed
Switch the catch to Throwable. Uncaught exceptions in a scheduled
threadpool executor will not report or log uncaught exceptions but will kill the thread causing unexplained timeouts in CS.
1 parent dbc7d80 commit e78bb1d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎engine/orchestration/src/com/cloud/agent/manager/DirectAgentAttache.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.atomic.AtomicInteger;
2525

2626
import org.apache.log4j.Logger;
27+
2728
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
2829

2930
import com.cloud.agent.api.Answer;
@@ -298,9 +299,10 @@ protected void runInContext() {
298299
} else {
299300
answer = new Answer(cmds[i], false, "Agent is disconnected");
300301
}
301-
} catch (Exception e) {
302-
s_logger.warn(log(seq, "Exception Caught while executing command"), e);
303-
answer = new Answer(cmds[i], false, e.toString());
302+
} catch (Throwable t) {
303+
// Catch Throwable as all exceptions will otherwise be eaten by the executor framework
304+
s_logger.warn(log(seq, "Throwable caught while executing command"), t);
305+
answer = new Answer(cmds[i], false, t.toString());
304306
}
305307
answers.add(answer);
306308
if (!answer.getResult() && stopOnError) {
@@ -317,8 +319,9 @@ protected void runInContext() {
317319
}
318320

319321
processAnswers(seq, resp);
320-
} catch (Exception e) {
321-
s_logger.warn(log(seq, "Exception caught "), e);
322+
} catch (Throwable t) {
323+
// This is pretty serious as processAnswers might not be called and the calling process is stuck waiting for the full timeout
324+
s_logger.error(log(seq, "Throwable caught in runInContext, this will cause the management to become unpredictable"), t);
322325
} finally {
323326
_outstandingTaskCount.decrementAndGet();
324327
scheduleFromQueue();

0 commit comments

Comments
 (0)