Reuse idle connections across requests - #48
Open
toots wants to merge 2 commits into
Open
Conversation
A write raising EPIPE on a peer-closed socket escaped through Lwt.async, leaving the in-flight request waiting on a response that could never arrive; the read side is now closed so the pending read errors out instead. Closing the channels is best-effort for the same reason, as a TLS shutdown over a dead socket raises and left the fd in CLOSE-WAIT.
Every request opened its own socket, paying a TCP and TLS handshake each time, although S3 and the S3-compatible endpoints all speak HTTP/1.1 keep-alive; idle connections are now pooled per (scheme, host, port) and handed back out, and a connection is only pooled when the response was framed well enough for the body to have been fully consumed. Peers reap idle connections on their own schedule, so an entry older than AWS_S3_POOL_MAX_IDLE_S (20s by default) is dropped rather than handed out, and a bodyless request that fails on a reused connection is retried once on a fresh one.
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.
Every request opened its own socket and paid a TCP and TLS handshake for it, although S3 and the S3-compatible endpoints all speak HTTP/1.1 keep-alive, so idle connections are now pooled per
(scheme, host, port)and handed back out; a connection is only pooled when the response was framed well enough for its body to have been fully consumed and did not ask forConnection: close.Peers reap idle connections on their own schedule -- Backblaze B2 aggressively so -- and handing out one the peer has already closed costs a failed request, so an entry idle for longer than
AWS_S3_POOL_MAX_IDLE_S(20s by default) is dropped instead, and a bodyless request that fails on a reused connection is retried once on a fresh one.The first commit is an independent lwt fix that reuse made visible: a write raising EPIPE on a peer-closed socket escaped through
Lwt.asyncand left the in-flight request waiting on a response that could never arrive, and a TLS shutdown over a dead socket did the same while leaving the fd in CLOSE-WAIT.