-
Notifications
You must be signed in to change notification settings - Fork 5
1026274: Worker Framework Shutdown hanging #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
1bb92b1
9475996
0046993
17da26b
99e56c2
509dd13
1c3eb1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,8 @@ public final class WorkerApplication extends Application<WorkerConfiguration> | |
{ | ||
private final long startTime = System.currentTimeMillis(); | ||
private static final Logger LOG = LoggerFactory.getLogger(WorkerApplication.class); | ||
private static final long SHUTDOWN_DURATION = 5 * 60 * 1000; // 5 minutes in milliseconds | ||
private static final int SHUTDOWN_LOG_INTERVAL = 15_000; // 15 seconds in milliseconds | ||
|
||
/** | ||
* Entry point for the asynchronous micro-service worker framework. | ||
|
@@ -143,25 +145,26 @@ public void start() { | |
|
||
@Override | ||
public void stop() { | ||
LOG.info("Worker stop requested, allowing in-progress tasks to complete."); | ||
LOG.info("Worker stop requested."); | ||
|
||
workerQueue.shutdownIncoming(); | ||
while (!wtp.isIdle()) { | ||
|
||
final long startTime = System.currentTimeMillis(); | ||
|
||
while(wtp.getBacklogSize() > 0 && System.currentTimeMillis() - startTime < SHUTDOWN_DURATION) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure about this strategy of trying to clear the backlog during shutdown? Trying to complete in-progress tasks makes sense but if I'm understanding this right it is intentionally allowing new tasks to begin that haven't been passed to the worker code yet. Wouldn't we be better to clear these backlog queues and let the next worker instance pick them up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The prefetched message have their delivery count increased and this goes towards the poison message identification. |
||
try { | ||
//The grace period will expire and the process killed so no need for time limit here | ||
LOG.trace("Awaiting the Worker Thread Pool to become idle, {} tasks in the backlog.", | ||
wtp.getBacklogSize()); | ||
Thread.sleep(1000); | ||
LOG.info("Allowing {} backlog tasks to complete, {} currently active.", wtp.getBacklogSize(), wtp.getApproxActiveCount()); | ||
andyreidz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Thread.sleep(SHUTDOWN_LOG_INTERVAL); | ||
} catch (final InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new RuntimeException(e); | ||
break; | ||
} | ||
} | ||
LOG.trace("Worker Thread Pool is idle."); | ||
wtp.shutdown(); | ||
andyreidz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
wtp.awaitTermination(10_000, TimeUnit.MILLISECONDS); | ||
} catch (InterruptedException e) { | ||
LOG.warn("Shutdown interrupted", e); | ||
wtp.awaitTermination(5, TimeUnit.MINUTES); | ||
} catch (final InterruptedException e) { | ||
LOG.error("Worker stop interrupted, in-progress tasks may not have completed.", e); | ||
Thread.currentThread().interrupt(); | ||
} | ||
workerQueue.shutdown(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.