Repository navigation
Conversation
…waits for the writer when it is full With a buffer, a send that finds the channel full no longer makes the session loop come round at once. The session sets a flag and the writer wakes it when it takes a message. Unset (0), the channel stays unbuffered and the behaviour is unchanged.
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.
Closes #783.
Adds
OutChanCapacity, the outgoing counterpart ofInChanCapacity(#736). It also stops the session loop from busy-spinning while that buffer is full.Changes
config.OutChanCapacity,SessionSettings.OutChanCapacity. The default is 0, an unbuffered channel and today's behaviour. A negative value is refused, as forInChanCapacity.initiator.go,acceptor.go.msgOutis made with that capacity, and the writer is given the session'smessageTaken.writeLooptakes an optionaltaken func(). It calls it after it takes each message and before it writes it: the channel has room from that moment.session.sendQueued. With a buffer, a send that finds it full callswaitForRoom:waitingForRoomand tries the send once more;notifyMessageOut();messageTakenclears the flag with a compare-and-swap and wakes the session once.The flag is set before the second try, so a take in between is either seen by that try or wakes the session. With no buffer the path is unchanged: a failed send still calls
notifyMessageOut().Disconnected (
messageOut == nil). With a buffer, the session no longer comes round for the queued messages. They wait for the next logon, as with any other queued message.Tests
New, in
out_chan_capacity_test.go:writeLoopcallstakenonce per message, in order;-race: every message arrives in order, and the loop comes round no more times than there are messages;Checks run
On macOS with Go 1.24.2:
go test -race ./...: every package passes butlog/mongo. That one panics inTearDownTestwithoutMONGODB_TEST_CXN, onmainas well.go vet ./...passes.golangci-lintv1.64.6, the version the Makefile pins: no findings.gofmt -l: nothing listed.The acceptance suite under
_testwas not run.