conn: fix read buffer size for batches with echo messages - #365
Open
rootkiller6788 wants to merge 1 commit into
Open
conn: fix read buffer size for batches with echo messages#365rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
The enlargeReadBuffer logic was inverted: the default echo read buffer was applied only when no buffered message had the Echo flag set, and skipped when the batch actually contained echo messages. As a result, batches that create rules (which set the Echo flag) were given a read buffer sized at 1024 bytes per message, which can be too small and lead to "recvmsg: no buffer space available" errors, while batches without echo messages wastefully allocated the large default buffer. Extract the buffer-size computation into readBufferSize so that it can be covered by a unit test.
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.
What
enlargeReadBufferinconn.gohad its echo-message detection inverted. The comment says the default (large) read buffer should be used when a batch contains messages with theEchoflag, but the code applied it when no message had the flag:Why it matters
Rule creation messages (
AddRule/InsertRule) setnetlink.Echoso the kernel echoes back each created rule. For those batches the code sized the socket receive buffer at onlylen(messages) * 1024, which can be too small for large batches and producenetlink receive: recvmsg: no buffer space available(see #350). Batches without echo messages, on the other hand, were given the multi-megabyte default buffer unnecessarily.Fix
Flags&netlink.Echo != 0.readBufferSize()method so it can be unit tested without a kernel.TestReadBufferSizecovering echo-less, echo, and large-echo batches.Verified with the full unit test suite (system tests excluded); the new test fails on the pre-fix code and passes with the fix.