Skip to content

fix(SyslogUdp): allow configuring the max UDP datagram length - #2049

Open
nabsei wants to merge 1 commit into
Seldaek:mainfrom
nabsei:fix-syslogudp-configurable-max-datagram-length-1826
Open

fix(SyslogUdp): allow configuring the max UDP datagram length#2049
nabsei wants to merge 1 commit into
Seldaek:mainfrom
nabsei:fix-syslogudp-configurable-max-datagram-length-1826

Conversation

@nabsei

@nabsei nabsei commented Jul 19, 2026

Copy link
Copy Markdown

What

UdpSocket::DATAGRAM_MAX_LENGTH (65023 bytes) is the largest a UDP payload can theoretically be, but a datagram that size gets fragmented at the IP level, and many routers/firewalls drop fragmented UDP packets outright. That silently truncates or loses log messages that exceed the path MTU on the way to the syslog receiver, even though nothing on the sending side reports an error.

Why this approach

An existing test (testLongMessagesAreTruncated) explicitly locks in the current 65023-byte behavior, and some setups over trusted/local networks may rely on it, so I didn't want to just lower the default and risk a behavior change / BC break. Instead, this adds an optional $maxLength constructor parameter to UdpSocket, threaded through SyslogUdpHandler's constructor (the entry point most users actually use), so a value that fits within the path MTU (eg. 1024) can be opted into. The default is unchanged.

Verification

  • Added regression tests covering: a custom $maxLength truncates at the new length, the default is preserved when not specified, and SyslogUdpHandler correctly threads the value through to its internal UdpSocket (verified via reflection, since $socket isn't otherwise inspectable from outside).
  • Full test suite passes (1182 tests); the only pre-existing failures are 3 unrelated ones in JsonFormatterTest/NormalizerFormatterTest/ErrorHandlerTest (confirmed identical on unmodified main), plus 30 skips for missing optional extensions (mongodb, redis, etc.) unrelated to this change.
  • phpstan analyse is clean on the changed files.

Honest caveat: I could not verify the actual real-world symptom (fragmented UDP getting dropped by a router/firewall) with a live network reproduction — that's not something reproducible over loopback, which doesn't share the same MTU/fragmentation-handling constraints as a real network path. Verification here is limited to code review and the unit tests described above.

Related issue

Fixes #1826


Disclosure: this PR was prepared with the assistance of Claude Code (Anthropic). The investigation, fix, and verification steps described above were done and checked by me.

UdpSocket::DATAGRAM_MAX_LENGTH (65023 bytes) is the largest a UDP
payload can theoretically be, but a datagram that size gets
fragmented at the IP level, and many routers/firewalls drop
fragmented UDP packets outright. That silently truncates or loses
log messages that exceed the path MTU on the way to the syslog
receiver, even though nothing on the sending side reports an error.

Add an optional $maxLength constructor parameter to UdpSocket and
thread it through SyslogUdpHandler, so a value that fits within the
path MTU (eg. 1024) can be used to avoid fragmentation. The default
is unchanged, so this is fully backwards compatible.

Fixes Seldaek#1826

Co-authored-by: Claude <noreply@anthropic.com>
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.

SyslogUdp logs gets truncated

1 participant