Repository navigation
server: keep session alive between sequential range requests - #402
Open
anishpentyala wants to merge 3 commits into
Open
anishpentyala wants to merge 3 commits into
anishpentyala wants to merge 3 commits into
Conversation
Added sessionActivity to track request activity and modified endSessionRequest to handle range requests more gracefully.
This branch has not been deployed
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.
Problem
qrcp sendstops the server as soon as the session's in-flight request count drops to zero. A downloader fetching the file in sequential ranges sends its next chunk request right after the previous one completes, but in between the count is zero: the first chunk gets a 206 and every following one gets a connection error.Reproduced with the included test (and by hand with two curl range requests carrying the session cookie): the second request fails with connection refused.
The session logic is meant to support exactly this case: "The server stops when that browser's requests (possibly several, for parallel chunks) are done."
Fix
When the last in-progress request of a session was a range request, the server waits a short grace period (2 seconds) before stopping, and stops only if no further request of the session has arrived meanwhile. A counter bumped on every admitted session request guards the timer: a timer left over from an earlier idle moment finds the counter changed and does nothing, so only the newest timer can stop the server. Plain full-file requests still stop the server as soon as they complete, so the common one-shot download flow is unchanged.
Two honest limitations:
Rangeheader (browsers often sendbytes=0-) now leaves the server up for 2 extra seconds after it finishes.Tests
TestSendSequentialRangesKeepServerUp: two sequential range GETs with the session cookie both return 206 and the correct bytes. Before the fix the second request fails with connection refused; after the fix both succeed.TestStaleRangeGraceTimerDoesNotStopServer(with the grace shortened via the now-varperiod): a timer from an earlier idle moment fires while the next chunk's grace is still running, and must not stop the server; the newest timer still does. Fails against a timer without the generation counter ("stale timer stopped the server during the next chunk's grace period"), passes with it.endSessionRequestnow takes the range flag, so the existing direct-call tests were updated to passfalse, keeping their immediate-stop assertions unchanged.go test ./server/is green. (The only failure in./...isconfig.TestNew, which panics with "no interfaces found" in this sandbox: pre-existing and environmental, unrelated to this change.)