Repository navigation
Close connections still open after the shutdown cut-off - #251
Merged
Merged
Conversation
After the grace period, S3Server cuts off running handlers with a 503. A response already returned has no handler to cancel. A GET body still streaming, or one the client stopped reading, kept its connection task, and the S3View and store it holds, alive after run() returned. The listener now wraps each connection in an IO type that fails every read and write once a close token is cancelled, and wakes a write waiting on the client. run() cancels it one second after the cut-off, then waits up to another second for the connections to go. Wrapping the response body instead would not work for a client that stopped reading: hyper waits on the socket and never polls the body. Fixes #239
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.
After the grace period,
S3Server::shutdown_oncuts off running handlers with a 503. A response that was already returned has no handler left to cancel. A GET whose body was still streaming kept its connection task, and theArc<S3View>and sled lock it holds, alive afterrun()returned. That matters for code that embedsS3Serverand keeps its runtime.spacectl serve-s3exits right afterrun(), so it wasn't affected.Why not wrap the response body, as the issue proposed. When a client stops reading, hyper is pending in
poll_flushon the socket and doesn't poll the body, so a body that ends at the cut-off never gets the chance. The connection's IO is where the wait happens, so that's where the cut-off goes.What changed. In the shutdown path each listener is a
ClosingListener, whose connections areClosingIo: aTcpStreamthat fails every read and write withConnectionAbortedonce a close token is cancelled. Each poll first polls the token's owned future, so a write waiting on the client is woken when the token fires.run()now:Response bodies aren't touched, so they keep their size hint and
Content-Length. The 503s go out before any connection is closed. Worst case, a stop takes 1 s longer than before.Test.
a_response_still_streaming_after_the_grace_period_is_closedPUTs 24 MiB, starts a GET from a client with a 4 KiB receive buffer, checks the head hascontent-lengthand notransfer-encoding, reads 64 KiB, then stops reading and signals. The store opens again oncerun()returns, while the client still holds its end. Withclose.cancel()removed, the reopen fails on the sled lock. Ran the shutdown suite three times.CHANGELOG updated.
Fixes #239