fix: graceful HTTP server shutdown with in-flight request draining - #1210
Open
enriquevalenzuelagalaxy wants to merge 5 commits into
Open
Conversation
Covers three scenarios: - close() waits for an in-flight request to complete before shutting down - close() completes normally when no requests are in-flight - close() before run() does not throw
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
… test - Add shuttingDown flag — trackInFlightRequests now returns 503 immediately when shutdown has started, preventing new requests from incrementing the counter after draining begins. Without this, sustained load could cause the drain to time out or a new request could slip in after counter=0 but before httpServer.close() runs. - Replace Thread.sleep(300) in test with explicit TimeoutException assertion to verify close() is blocked — removes SonarQube S2925 (Bug) violation.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 3e7d4a2. Configure here.
|
I have read the CLA Document and I hereby sign the CLA |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




PR Description
Adds graceful HTTP server shutdown to
Runner. Whenclose()is called, the server now waits for any in-flight HTTP requests to complete before closing the Vert.xHttpServer, preventing abrupt connection resets under load or during rolling restarts.Changes:
trackInFlightRequests()— wraps the request handler to atomically increment/decrement an in-flight counter, guarded against double-counting viaAtomicBooleanper requestwaitForInFlightRequestsToComplete()— blocks the shutdown thread (up to 20 seconds) usingObject.wait/notifyAllon a monitorgracefulHttpShutdown()— drains in-flight requests then closes theHttpServervia its asyncclose()with a latchclose()to callgracefulHttpShutdown()before closing other resourceshttpServerpromoted from local variable tovolatileinstance field soclose()can reference itFixed Issue(s)
Documentation
doc-change-requiredlabel to this PR if updates are required.Changelog
Testing
RunnerGracefulShutdownTestcovers three scenarios using a real embedded Vert.x server:closeWaitsForInFlightRequestBeforeShuttingDown— verifiesclose()blocks until a slow in-flight request completes before returningcloseCompletesNormallyWithNoInFlightRequests— verifiesclose()doesn't block when idlecloseBeforeRunDoesNotThrow— verifies the null-guard onhttpServeris correctNote
Medium Risk
Changes core HTTP lifecycle and shutdown ordering for a signing service; bounded timeouts mean very long requests may still be cut off, but signing logic is unchanged.
Overview
Runner.close()now drains active HTTP work before tearing down other resources, so rolling restarts and shutdown under load are less likely to reset connections mid-signing.Shutdown sets a
shuttingDownflag and wraps the Vert.x request handler withtrackInFlightRequests, which counts in-flight requests, rejects new ones with 503 once shutdown has started, and decrements on response completion (with guards against double-counting).gracefulHttpShutdownwaits up to 20 seconds for the counter to reach zero, then closes theHttpServerasynchronously with a bounded wait. The server instance is stored on the runner soclose()can run this path even whenrun()was never started (null-safe).RunnerGracefulShutdownTestexercises blockingclose()until a slow handler finishes, idle shutdown, andclose()beforerun().Reviewed by Cursor Bugbot for commit bd4bb58. Bugbot is set up for automated code reviews on this repo. Configure here.