Repository navigation
Conversation
NetConn always called SetReadLimit(-1), so a limit set before NetConn was silently dropped while one set after it applied. NetConn now disables the limit only if SetReadLimit was never called on the Conn.
The Wasm Conn tracks SetReadLimit calls separately from the native Conn, so the same four cases run in the browser against the echo server.
The fix-close-race-net-errclosed branch adds a test at the same place in ws_js_test.go, and the two insertions conflict on merge.
mafredri
force-pushed
the
mafredri/netconn-keep-read-limit
branch
from
October 30, 2026 15:18
cb29345 to
ef9faa0
Compare
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.
NetConncalledSetReadLimit(-1)every time, so the outcome depended on call order: a limit set afterNetConnapplied, and a limit set before it was dropped without an error. Code that set a limit and then calledNetConnhad no limit at all.NetConnnow disables the limit only ifSetReadLimitwas never called on theConn. A limit set before or afterNetConnis kept, and so is an explicitSetReadLimit(-1). Callers that never callSetReadLimitsee no change:NetConnstill disables the 32768 byte default.Behavior change: if you call
SetReadLimit(n)beforeNetConn, that limit is now enforced. Reading a message larger thannbytes fails withErrMessageTooBig, asSetReadLimitdocuments; before this change the message was read in full. To keep the old behavior, remove theSetReadLimitcall or pass-1.New tests cover a limit set before
NetConn, set after it, never set, and set to-1before it, on native and on Wasm in the browser. The before-NetConntest fails on master on both platforms../ci/lint.sh,go test -race ./...and the Wasm browser test pass.Refs #244 (this PR does not add the
ReadLimitoption field).Decision log
SetReadLimitmust followNetConn: documentation alone leaves the call-order problem for every caller.ReadLimitfield inAcceptOptions/DialOptionshere: that is a separate API decision on Add ReadLimit to Option structs #244, and the field would need this rule anyway, becauseNetConnwould otherwise discard it.atomic.Boolon bothConntypes records thatSetReadLimitwas called:SetReadLimittakes no lock,Connmethods may run concurrently, and the limit itself is already atomic.SetReadLimitandNetConncalled at the same time with no ordering can still end with the limit disabled. Closing that would need a lock or a sentinel limit value, which this PR does not add.