Copilot commented on code in PR #11330: URL: https://github.com/apache/cloudstack/pull/11330#discussion_r2239416974
########## agent/src/main/java/com/cloud/agent/Agent.java: ########## @@ -968,9 +968,11 @@ private Answer migrateAgentToOtherMS(final MigrateAgentConnectionCommand cmd) { if (CollectionUtils.isNotEmpty(cmd.getMsList())) { processManagementServerList(cmd.getMsList(), cmd.getAvoidMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval(), false); } - Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("MigrateAgentConnection-Job")).schedule(() -> { + ScheduledExecutorService migrateAgentConnectionService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("MigrateAgentConnection-Job")); + migrateAgentConnectionService.schedule(() -> { migrateAgentConnection(cmd.getAvoidMsList()); }, 3, TimeUnit.SECONDS); + migrateAgentConnectionService.shutdown(); Review Comment: The executor service is shut down immediately after scheduling the task, which will prevent the scheduled task from executing. The shutdown should be called after the task completes, not immediately after scheduling. ```suggestion ScheduledFuture<?> future = migrateAgentConnectionService.schedule(() -> { migrateAgentConnection(cmd.getAvoidMsList()); }, 3, TimeUnit.SECONDS); try { future.get(); // Wait for the task to complete } catch (Exception e) { logger.error("Error while waiting for migrateAgentConnection task to complete", e); } finally { migrateAgentConnectionService.shutdown(); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org