Repository navigation
Server: a frame's payload buffer grows with the bytes received - #167
Merged
Merged
Conversation
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.
Why
readPacketallocated a buffer of the length the frame header declares, up to 65535 bytes, before reading any of the payload. A connection that sent a header declaring a long payload and then stopped held that whole buffer until the read deadline ended. An ordinary idle connection holds a few KB, so each half-sent frame cost many times that, and the total scaled with the number of open connections (-max-conns, default 4096).Change
server/proto.go:readPacketstarts the payload buffer atreadChunk(2048 bytes, or the declared length if smaller) and grows it by doubling as bytes arrive, so the memory held tracks what was received. Frames that arrive whole read exactly as before.server/proto_alloc_test.go: payload sizes around the chunk and doubling boundaries and the maximum round-trip intact; truncated frames return an EOF error; a header declaring the maximum with no payload allocates at most 8 KB per call (65 KB before).Tests
go vetandgo test -race ./serverpass.readChunkto 65535 makesTestReadPacketDeclaredSizeNotAllocatedfail (66074 bytes per call).python3 tools/features.py,python3 tools/site.py,python3 tools/repo_check.pyandscripts/check-deploy.shpass.Evidence
Before the change, a throwaway test (not in this PR) opened connections to a test server from one address, each sending only the three header bytes declaring 65535: the per-address limit admitted 32 of them and the heap grew by about 2170 KB, roughly 68 KB each.
Not in this change
The read deadline, the packet size limit and the connection limits are unchanged.
Overlap
None open on
server/proto.go. Touches CHANGELOG.md,site/index.htmlandsite/data.json, which other open PRs also change.Developed with AI agent assistance.