Repository navigation
Description
try_read_delimited_message (command/src/channel.rs) has a third peer-length rejection branch
besides the two in #1428. It returns without consuming and without moving a readiness
bit, exactly like the oversize branch did — but unlike that one, the peer that triggers it has done
nothing wrong, and the correct recovery is not a close.
All line numbers below are at 595920e91c4528f0554410b904b45d543c88e467.
The branch
command/src/channel.rs:626-632, reached when the declared length is in range but the whole frame
is not buffered yet:
if self.front_buf.available_space() == 0 {
if self.front_buf.capacity() >= self.max_buffer_size {
return Err(ChannelError::BufferFull {
capacity: self.front_buf.capacity(),
max: self.max_buffer_size,
});
}No consume, no error!, no readiness change. Same shape as #1428's oversize branch.
Reachability, step by step
Buffer::consume (command/src/buffer/growable.rs:86-94) compacts the buffer only when the read
cursor has passed the halfway mark:
pub fn consume(&mut self, count: usize) -> usize {
let cnt = cmp::min(count, self.available_data());
self.position += cnt;
if self.position > self.capacity / 2 {
self.shift();
}
cnt
}So, with capacity C already at max_buffer_size:
Buffer::fill(command/src/buffer/growable.rs:97-105) shifts whenever a read fills the buffer
to its end, so once the front buffer is full we haveposition == 0,end == C,
available_data() == C.- The parser decodes a frame of length
L <= C / 2and callsfront_buf.consume(L)
(command/src/channel.rs:609).positionbecomesL, which is not> C / 2, so no shift. - Now
available_space() == C - end == 0whileavailable_data() == C - L. - The next frame declares
MwithC - L < M <= C. It passes both guards — it is at least
delimiter_size()and at mostmax_buffer_size— butbuffer.len() == C - L < M, so the decode
branch at:596is skipped and control falls through to:626, whereavailable_space() == 0
andcapacity() >= max_buffer_sizeboth hold.Err(BufferFull).
With bin/config.toml's max_command_buffer_size = 163840 that is a frame of at most 81 920 bytes
followed by one larger than 81 920 — ordinary LoadState territory, from a peer whose every frame
is correctly formed and under the shared ceiling.
Nothing can recover it
The buffer holds C - L pending bytes at offset L, and a single Buffer::shift
(command/src/buffer/growable.rs:121-135) would move them to offset 0 and hand back L bytes of
space — enough for the frame to complete. But no code path can reach that shift again:
- The only three
front_bufmutators that can trigger it arefill(:375,:509),consume
(:573,:609) andshrink(:800). fillneeds a successful read.Channel::readable(:315-337) seesavailable_space() == 0,
grow_sizereturnsNoneat the ceiling, and it executesself.interest.remove(Ready::READABLE)
(:335) and breaks. Every laterreadable()returnsErr(Connection(None)).consumeneeds either a decoded frame or an under-delimiter length; the parse returns at:628
before reaching either.try_shrink_front_buf(:786-801) early-returns unlessavailable_data() * 4 < initial_buffer_size, which is false withC - Lbytes pending — and it callsBuffer::shrink,
notshift, anyway.
Downstream is #1428's story verbatim: extract_messages (bin/src/command/sessions.rs:577-607)
discards the error with the bare Err(_) at :590 and returns immediately because the capacity did
not change; ClientSession::ready (:165) and WorkerSession::ready (:549) close only on
readiness.is_error() || is_hup(); wants_to_tick (:612-615) keys on the same bits, so the
session is not even re-scheduled. The session is wedged permanently, holding its fd and a full
max_command_buffer_size buffer, with nothing logged.
Why the #1428 fix deliberately does not cover it
#1428's oversize branch now logs and marks the channel Ready::ERROR, because a length above the
ceiling can never be satisfied by a buffer bounded at that ceiling — no recovery exists, so dropping
the peer is the only exit.
That reasoning does not transfer here. The frame can complete: the bytes are already buffered, the
declared length is under the ceiling, and a compaction makes room. Marking the channel errored would
drop a conforming peer over an internal buffer-management detail — the precise conflation #1428's
fix was written to avoid. The fix belongs in the buffer management, not in the close path: compact
the front buffer when the declared frame fits the capacity but not the remaining space, and only
then consider the frame unsatisfiable.
What I verified, and what I did not
Verified by reading command/src/channel.rs, command/src/buffer/growable.rs and
bin/src/command/sessions.rs at 595920e9, and by tracing every front_buf mutator in the file.
Not verified: no unit test drives a real Channel pair into this state yet, and there is no
end-to-end reproduction against a running sōzu master. The step-2 precondition (fill always
compacts when it reaches the end of the buffer) is read from Buffer::fill, not measured. Found
while fixing #1428; filed separately because the recovery is different.
Activity
fix(command): drop a peer declaring a frame length above the channel …
fix(command): drop a peer declaring a frame length above the channel …
fix(command): compact the front buffer instead of declaring it full
fix(command): drop a peer declaring a frame length above the channel …
fix(command): compact the front buffer instead of declaring it full
fix(command): compact the front buffer instead of declaring it full
fix(command): re-arm READABLE on the read failures a channel can pars…
fix(command): compact the front buffer instead of declaring it full (s…
fix(command): re-arm READABLE on the read failures a channel can pars…
fix(command): re-arm READABLE on the read failures a channel can pars…
fix(command): re-arm READABLE on the read failures a channel can pars…