Repository navigation
buffer: drop the reader reference after copying - #17695
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Netstack TCP endpoints reuse one `io.LimitedReader` across writes, and `WriteFromReaderAndLimitedReader()` left the caller's reader in `lr.R` after the copy. For write(2) and writev(2) that reader is a field of the socket, so a closed socket stayed reachable until its endpoint was freed, which can be a minute or more after close in FIN_WAIT_2 or TIME_WAIT. Servers that churn short connections held that memory the whole time. Set `lr.R` to nil once `io.Copy()` returns. The `LimitedReader` is still reused, so no `LimitedReader` is allocated per write. On nginx serving 80,000 fresh connections, peak server memory drops by 18% on systrap (251 to 205 MB). Reviewed and tested by me. Assisted-by: Claude Code FUTURE_COPYBARA_INTEGRATE_REVIEW=#17685 from sam10ridh:Samridh/reader-retention-20261115 8f3c49f PiperOrigin-RevId: 1022522754
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.
buffer: drop the reader reference after copying
Netstack TCP endpoints reuse one
io.LimitedReaderacross writes, andWriteFromReaderAndLimitedReader()left the caller's reader inlr.Rafter the copy. For write(2) and writev(2) that reader is a field of the
socket, so a closed socket stayed reachable until its endpoint was
freed, which can be a minute or more after close in FIN_WAIT_2 or
TIME_WAIT. Servers that churn short connections held that memory the
whole time.
Set
lr.Rto nil onceio.Copy()returns. TheLimitedReaderis stillreused, so no
LimitedReaderis allocated per write.On nginx serving 80,000 fresh connections, peak server memory drops by
18% on systrap (251 to 205 MB).
Reviewed and tested by me.
Assisted-by: Claude Code
FUTURE_COPYBARA_INTEGRATE_REVIEW=#17685 from sam10ridh:Samridh/reader-retention-20261115 8f3c49f