Skip to content

new: configurable UDP receive buffer (SO_RCVBUF), default 1 MB#195

Merged
gralin merged 1 commit into
masterfrom
new-udp-receive-buffer
Jul 3, 2026
Merged

new: configurable UDP receive buffer (SO_RCVBUF), default 1 MB#195
gralin merged 1 commit into
masterfrom
new-udp-receive-buffer

Conversation

@gralin

@gralin gralin commented Jul 3, 2026

Copy link
Copy Markdown
Member

Follow-up to the #132 investigation. The UDP transport never set the socket receive buffer, so it used the OS default (64 KB on Windows). Under a burst of incoming messages — e.g. event notifications delivered faster than a slow OnEventNotify handler drains them — the buffer overflows and the OS silently drops packets. That is the "some notifications are missed" in #132.

Change

  • Default the UDP receive buffer to 1 MB.
  • Expose a ReceiveBufferSize property that can be changed at any time, including after Start() — it is applied to the live socket(s) immediately.

Why 1 MB works on PC and Raspberry Pi

Over-requesting SO_RCVBUF is never fatal:

  • Windows honors the full 1 MB (16× the 64 KB default).
  • Linux / Raspberry Pi silently clamp to net.core.rmem_max (~208 KB default) — no error, only the clamped amount is allocated (trivial even on a 512 MB Pi). To go higher you raise net.core.rmem_max via sysctl.

Verified

  • Build + 119 tests pass.
  • The exact scenario that dropped 982/3000 at 64 KB now delivers 3000/3000, 0 dropped at 1 MB.
  • ReceiveBufferSize reads back 1048576 by default and successfully changes to 4 MB after Start() (applied to the live socket).

Note: this raises the burst threshold; the deeper guidance for #132 (return fast from OnEventNotify, offload heavy work) still stands.

The UDP transport left the socket receive buffer at the OS default (64 KB on Windows), so a
burst of incoming messages could overflow it and the OS silently dropped packets - e.g. a fast
run of event notifications where the handler is slow (#132). Set it to 1 MB by default and
expose a ReceiveBufferSize property that can be changed at any time, including after Start()
(applied to the live socket). Over-requesting is honored on Windows and clamped to
net.core.rmem_max on Linux/Raspberry Pi - never fatal, so no per-OS handling is needed.
@gralin gralin merged commit d40e2ce into master Jul 3, 2026
4 checks passed
@gralin gralin deleted the new-udp-receive-buffer branch July 3, 2026 11:15
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