Skip to content

UDP: receive datagrams up to the IPv4 maximum, a datagram over 2000 bytes ended all capture - #427

Merged
janwilmans merged 1 commit into
CobaltFusion:developfrom
panayiotisp:fix/udp-large-datagrams
Nov 4, 2026
Merged

janwilmans merged 1 commit into
CobaltFusion:developfrom
panayiotisp:fix/udp-large-datagrams

Conversation

@panayiotisp

Copy link
Copy Markdown
Contributor

A UDP datagram larger than 2000 bytes crashes DebugView++.

What happens. SocketReader receives into a std::array<char, 2000>. A larger datagram fails the receive with WSAEMSGSIZE, and WSAGetOverlappedResult throws. LogSources::Listen rethrows on the thread that reads every source, so an "Exception occurred" box appears. The text is "A message sent on a datagram socket was larger than the internal message buffer...", from LogSources.cpp:221. When the box is closed the program ends, so all capture stops, not only UDP.

Why it matters. Logging frameworks send large datagrams routinely: log4net's UdpAppender, for example, sends an exception with its stack trace as a single datagram. On one development machine of ours, 298 of 86,723 logged messages were over 2000 bytes (the largest 63,846), and most days' logs had at least one. That makes the UDP source unusable as a log viewer.

Fix. The buffer is now 65536 bytes. That holds the largest UDP payload over IPv4 (65,507 bytes), and the socket is AF_INET, so the receive can no longer fail this way. SocketReader is created with make_unique in LogSources::AddUDPReader, so the larger member is on the heap.

Test. LogSourceUdpReaderReceivesLargeDatagrams sends datagrams of 100, 2000, 2001, 10,000 and 65,507 bytes to a UDP reader on port 2035, one at a time, and expects to receive all five.

Checked, with VS 18 (MSVC 14.51), Release x64:

  • The new test passes. With the buffer put back to 2000 it fails: it receives { 100, 2000 } and nothing after.
  • ctest -C Release passes, with the same GTEST_FILTER as CI.
  • The patched Debugviewpp.exe, listening on a UDP port, received messages of 1999, 2000, 2001, 2500, 9000 and 63,846 bytes, and kept receiving afterwards, with no exception box.

🤖 Generated with Claude Code

…2000-byte buffer ended all capture

The UDP source received into a 2000-byte buffer. A larger datagram fails the receive with WSAEMSGSIZE, that
exception is rethrown on the thread that reads all sources, an "Exception occurred" box is shown, and the
program ends when it is closed. Log frameworks send larger datagrams routinely, log4net's UdpAppender sends
an exception with its stack trace as a single datagram, so DebugView++ could not be used as a UDP log viewer.

The buffer is now 65536 bytes, room for the largest UDP datagram over IPv4 (65507 bytes), so the receive can
no longer fail this way.

LogSourceUdpReaderReceivesLargeDatagrams sends datagrams of 100, 2000, 2001, 10000 and 65507 bytes to a UDP
reader and expects all of them. With the old buffer it receives only the first two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@janwilmans janwilmans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the change!

@janwilmans
janwilmans merged commit 279fd11 into CobaltFusion:develop Nov 4, 2026
1 check passed
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.

2 participants