Skip to content

Commit

Permalink
Fixed ExpirationService not shutting down Executor (#835)
Browse files Browse the repository at this point in the history
When shutting down the server the Executor Threads in ScheduledExpirationService instances were not terminated, resulting in a hanging server that would not shut down.
  • Loading branch information
hylkevds committed May 1, 2024
1 parent 2092693 commit 432b3f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions broker/src/main/java/io/moquette/broker/PostOffice.java
Expand Up @@ -1019,6 +1019,7 @@ public RouteResult routeCommand(String clientId, String actionDescription, Calla

public void terminate() {
willExpirationService.shutdown();
retainedMessagesExpirationService.shutdown();
sessionLoops.terminate();
}

Expand Down
Expand Up @@ -25,13 +25,14 @@ public class ScheduledExpirationService<T extends Expirable> {
private final ScheduledFuture<?> expiredEntityTask;
private final Clock clock;
private final Consumer<T> action;
private final ScheduledExecutorService actionsExecutor;

private final Map<String, ExpirableTracker<T>> expiringEntitiesCache = new HashMap<>();

public ScheduledExpirationService(Clock clock, Consumer<T> action) {
this.clock = clock;
this.action = action;
ScheduledExecutorService actionsExecutor = Executors.newSingleThreadScheduledExecutor();
this.actionsExecutor = Executors.newSingleThreadScheduledExecutor();
this.expiredEntityTask = actionsExecutor.scheduleWithFixedDelay(this::checkExpiredEntities,
FIRER_TASK_INTERVAL.getSeconds(), FIRER_TASK_INTERVAL.getSeconds(),
TimeUnit.SECONDS);
Expand Down Expand Up @@ -71,5 +72,6 @@ public void shutdown() {
LOG.warn("Can't cancel the execution of expired entities task, was already cancelled? {}, was done? {}",
expiredEntityTask.isCancelled(), expiredEntityTask.isDone());
}
actionsExecutor.shutdownNow();
}
}

0 comments on commit 432b3f0

Please sign in to comment.