curator icon indicating copy to clipboard operation
curator copied to clipboard

[CURATOR-469] Give background task a chance to execute in CuratorFramework.close()

Open jira-importer opened this issue 7 years ago • 1 comments

The current impl of CuratorFramework.close() does not really give background task a chance to finish. The following steps are currently taken in close().

1. Set the state to STOPPED
2. Call executorService.shutdownNow();
3. Call executorService.awaitTermination(maxCloseWaitMs, TimeUnit.MILLISECONDS);

After step 1 is complete any background task accessing curator will get an IllegalStateException (See CURATOR-467). Step 2 interrupts actively running task and dequeues any task waiting run. In step 3 I wonder why bother to wait?

Making close do the following is one possible way to give background task a chance to run.

1. Call executorService.shutdown();
2. Call executorService.awaitTermination(maxCloseWaitMs, TimeUnit.MILLISECONDS);
3. Set the state to STOPPED
4. Call executorService.shutdownNow();

Step 1 prevents new task from being added, but gives currently running and queued task a chance. In step 2 we wait up to the user configured time for task to complete. In step 3 and 4 we cause any background task that are still running to fail.


Originally reported by kturner, imported from: Give background task a chance to execute in CuratorFramework.close()
  • assignee: randgalt
  • status: Open
  • priority: Major
  • resolution: Unresolved
  • imported: 2025-01-21

jira-importer avatar Jun 05 '18 20:06 jira-importer

cammckenzie:

This sounds like a sensible approach, and I think it will fix a number of issues:

CURATOR-448, CURATOR-467 and CURATOR-468

Would you like to submit a PR for this fix?

jira-importer avatar Jun 05 '18 23:06 jira-importer