ppkarwasz opened a new issue, #4517:
URL: https://github.com/apache/logging-log4j2/issues/4517

   #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 #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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to