Repository navigation
Don't flush empty buffers - #347
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1b26cf6d0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| throw new InvalidMessageException( | ||
| MESSAGE_TOO_LONG, builder.toString()); |
There was a problem hiding this comment.
Update the existing multibyte-overflow test for the new exception
When the worker flushes the first valid gauge before badgauge is queued, this branch now reports InvalidMessageException, but NonBlockingStatsDClientTest.sends_gauge_without_truncation still unconditionally requires BufferOverflowException at line 345. If the first gauge remains buffered, the retry at line 117 still reports BufferOverflowException. Consequently, that existing test now passes or fails depending on worker scheduling; both outcomes are reproducible with its oversized payload. Update the existing assertion alongside this exception change, accounting for both buffer states, to avoid intermittent suite failures.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 72bec24. An empty buffer that overflows now rethrows the BufferOverflowException, still without flushing the buffer. Both buffer states report the same exception, so sends_gauge_without_truncation is deterministic again. StatsDProcessorTest covers both states.
🤖 Generated by Claude Opus 5.5 with Claude Code
The remaining() check still reserves a byte for the separator the processor wrote between messages before messages carried their own newline. An exact fit therefore flushed the current buffer first, even when it was empty, and a message that exactly filled the rest of a buffer went to a new one. When a multibyte message overflowed an empty buffer, that empty buffer was flushed before the retry failed the same way. Drop the extra byte. When an empty buffer overflows, rethrow the BufferOverflowException without flushing it, so handlers see the same exception whether or not an earlier message is buffered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72bec24 to
f18cb4f
Compare
The
remaining() < lowerBoundSize + 1check inStatsDProcessorstill reserves a byte for the separator the processor wrote between messages (48823d8), before messages ended with their own newline. As a result:Separately, when a multibyte message overflows an empty buffer, that empty buffer is flushed before the retry fails the same way.
The fix drops the
+ 1. When an empty buffer overflows, it rethrows theBufferOverflowExceptionwithout flushing the buffer. Handlers still seeBufferOverflowExceptionfor multibyte messages that don't fit, whether or not an earlier message is buffered, assends_gauge_without_truncationexpects.Behaviour change: a message that exactly fills the rest of a buffer now joins it, so the client sends slightly fewer packets and its
packets_senttelemetry drops a little.Testing: the flush decisions live in the processing loop, not in
StatsDProcessor.Encoder, soStatsDProcessorTestdrives a processor and reads its outbound queue. It fails on any empty packet. It covers an exact fit, an exact fit into the rest of a packet, and a multibyte overflow both with an empty buffer and after a buffered chunk; both overflow cases expectBufferOverflowException. Onmasterthe first three fail and the last passes; all four pass with this change. I ran the full suite on JDK 22 with--release 8outside Maven. It has the same 31 Unix-socket failures asmaster, where jnr-ffi cannot load on macOS arm64.CardinalityOverrideTest's 1-second timeouts flaked occasionally on bothmasterand this branch in interleaved runs.🤖 Generated with Claude Code