Skip to content

Truncate oversized UDP datagrams instead of dropping them #4517

Open

Description

@ppkarwasz

#4336 (fixing #4333) caps the payload of DatagramOutputStream at 65,507 bytes, the IPv4 UDP limit. When a datagram would exceed that limit, the whole datagram is dropped:

  • copy() appends nothing more as soon as the next write call does not fit completely, and only counts the remaining length;
  • flush() then discards everything that was buffered and logs a WARN.

UDP is mostly used to send RFC 5424 syslog messages, and RFC 5424 receivers must tolerate truncated messages. A layout that writes an event in several write calls loses all of them, even when most of the message fits.

Proposed fix

  • copy(): append as many bytes as still fit, i.e. min(length, MAX_DATAGRAM_LENGTH - data.size()), even if that cuts a write call in the middle, and only count the bytes that do not fit.
  • flush(): always send the buffered bytes; if anything was cut, log a WARN such as UDP datagram truncated from N to 65507 bytes.
  • Footer: it is appended last, so it is the first part to be cut. Rfc5424Layout does not use one, so no space is reserved for it.

Tests

  • Replace the expectation that an oversized datagram is dropped with a check that exactly 65,507 bytes are sent and that they start with the beginning of the event.
  • Add a case where the event is written in several write calls and the cut falls inside one of them.

Notes

  • The cut can fall inside a multi-byte UTF-8 character. Receivers that truncate messages themselves face the same situation.
  • Layouts producing JSON (e.g. GELF) will send a truncated document instead of nothing. Before Grow DatagramOutputStream buffer and drop oversized UDP payloads #4336 such an event was lost too, because DatagramSocket.send failed with Message too long.

Since #4336 is part of 2.26.2 (#4385), this should be fixed before that release.

Activity

  1. added
    bug
    on Nov 24, 2026
  2. added this to the 2.27.0 milestone on Nov 24, 2026
  3. added
    priority: P1
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugport-to-2.25.xport-to-2.26.xpriority: P1

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions