Skip to content

Commit 26e5d3c

Browse files
sliceofapplepiesureshanaparti
authored andcommitted
Wrap async event bus publish in ManagedContextRunnable for DB connection safety
The sole subscriber (ApiServer.handleAsyncJobPublishEvent) performs DAO reads (getUserIncludingRemoved, getAccount, findById) inside its callback. Without ManagedContextRunnable, the EventBus thread would not have proper TransactionLegacy lifecycle management, risking DB connection leaks.
1 parent 68c69df commit 26e5d3c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,13 @@ protected AsyncJobManagerImpl() {
14001400

14011401
private void publishOnEventBus(AsyncJob job, String jobEvent) {
14021402
try {
1403-
_eventBusPublisher.submit(() ->
1404-
_messageBus.publish(null, AsyncJob.Topics.JOB_EVENT_PUBLISH, PublishScope.LOCAL,
1405-
new Pair<AsyncJob, String>(job, jobEvent)));
1403+
_eventBusPublisher.submit(new ManagedContextRunnable() {
1404+
@Override
1405+
protected void runInContext() {
1406+
_messageBus.publish(null, AsyncJob.Topics.JOB_EVENT_PUBLISH, PublishScope.LOCAL,
1407+
new Pair<AsyncJob, String>(job, jobEvent));
1408+
}
1409+
});
14061410
} catch (RejectedExecutionException e) {
14071411
s_logger.warn("Failed to publish async job event, event bus publisher is shut down", e);
14081412
}

0 commit comments

Comments
 (0)