ARTEMIS-1852 PageCursorProvider is leaking cleanup tasks while stopping

PageCursorProviderImpl is not handling any pending cleanup tasks
on stop, leaving paging enabled due to the remaining pages to be
cleared up.
PagingStoreImpl is responsible to trigger the flushing of pending
tasks on PageCursorProviderImpl before stopping it and to try to
execute any remaining tasks on the owned common executor, before
shutting it down.
It fixes testTopicsWithNonDurableSubscription.
This commit is contained in:
Francesco Nigro 2018-05-07 11:47:26 +02:00
parent 26ccd63b1d
commit d31d6e8131
2 changed files with 18 additions and 4 deletions

View File

@ -239,8 +239,10 @@ public class PageCursorProviderImpl implements PageCursorProvider {
for (PageSubscription cursor : activeCursors.values()) {
cursor.stop();
}
executor.shutdownNow();
final int pendingCleanupTasks = scheduledCleanup.get();
if (pendingCleanupTasks > 0) {
logger.tracef("Stopping with %d cleanup tasks to be completed yet", pendingCleanupTasks);
}
}
private void waitForFuture() {

View File

@ -348,11 +348,23 @@ public class PagingStoreImpl implements PagingStore {
@Override
public synchronized void stop() throws Exception {
if (running) {
cursorProvider.flushExecutors();
cursorProvider.stop();
running = false;
final List<Runnable> pendingTasks = new ArrayList<>();
final int pendingTasksWhileShuttingDown = executor.shutdownNow(pendingTasks::add);
if (pendingTasksWhileShuttingDown > 0) {
logger.tracef("Try executing %d pending tasks on stop", pendingTasksWhileShuttingDown);
for (Runnable pendingTask : pendingTasks) {
try {
pendingTask.run();
} catch (Throwable t) {
logger.warn("Error while executing a pending task on shutdown", t);
}
}
}
executor.shutdownNow();
running = false;
if (currentPage != null) {
currentPage.close(false);