Skip to content

conn: fix read buffer size for batches with echo messages - #365

Open
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-read-buffer-echo-flag
Open

conn: fix read buffer size for batches with echo messages#365
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-read-buffer-echo-flag

Conversation

@rootkiller6788

Copy link
Copy Markdown

What

enlargeReadBuffer in conn.go had its echo-message detection inverted. The comment says the default (large) read buffer should be used when a batch contains messages with the Echo flag, but the code applied it when no message had the flag:

if msg.Header.Flags&netlink.Echo == 0 {
    bufferSize = cc.getDefaultEchoReadBuffer()
    break
}

Why it matters

Rule creation messages (AddRule/InsertRule) set netlink.Echo so the kernel echoes back each created rule. For those batches the code sized the socket receive buffer at only len(messages) * 1024, which can be too small for large batches and produce netlink 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

  • Invert the condition to Flags&netlink.Echo != 0.
  • Extract the buffer-size computation into a readBufferSize() method so it can be unit tested without a kernel.
  • Add TestReadBufferSize covering 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant