Repository navigation
Description
Channel::read_message_nonblocking re-arms Ready::READABLE only on the NothingRead path. Every error path propagates through ? first and skips the re-arm, and readable() then refuses to run for the rest of the drain. Socket bytes already pending are stranded on a session that nothing will schedule again.
Found while reviewing the fix for #1436; it is a second wedge of the same family, pre-existing and not that changeset's shape, so it is filed separately rather than widened into it.
The path
At 95dee167, command/src/channel.rs:504-511:
fn read_message_nonblocking(&mut self) -> Result<Rx, ChannelError> {
if let Some(message) = self.try_read_delimited_message()? { // :505
self.try_shrink_front_buf();
return Ok(message);
}
self.interest.insert(Ready::READABLE); // :510
Err(ChannelError::NothingRead)
}The ? at :505 is the whole bug. Ok(None) falls through to :510 and re-arms. Err(_) returns immediately and does not. readable() then early-returns at :344:
if !(self.interest & self.readiness).is_readable() {
return Err(ChannelError::Connection(None));
}so once the interest bit is gone, nothing in the drain loop can refill the front buffer from the socket.
Reachable today via MessageLengthUnderDelimiter
channel.rs:605-611 rejects a frame declaring a length below the delimiter and consumes delimiter_size() bytes so the buffer can re-sync. The comment two lines above (:600-604) says the consume exists "so the channel can re-sync on the peer's next frame" — true of bytes already in front_buf, false of bytes still in the socket, because this same return skips the re-arm.
Measured on the #1436 review branch, capacity 64, one 94-byte peer write (64 buffered, 30 left in the socket):
ATK tick1 result=NewRequest(LoadState) pending=16 space=40 wants_to_tick=false interest_rd=false
The session delivers one good request, then parks: 30 bytes unread in the socket, wants_to_tick=false, no hup, no error, interest_rd=false. Nothing retries it. Only a malformed peer reaches this, unlike #1436, which is why the severity is lower — but a malformed peer is exactly what a framing layer exists to survive, and the surrounding comment claims it does.
Two gates, not one — this section was wrong
Corrected 2026-09-22. This issue originally claimed the drain loop is not what stops, that readable() alone is the block, and that widening extract_messages' anchor "does not help". The implementation measured all four combinations:
| tree state | test |
|---|---|
| unmodified | RED |
| channel re-arm only | RED |
| session anchor only | RED |
| both | GREEN |
Each half is individually insufficient and individually necessary. readable() drops READABLE at the ceiling, so the parse must re-arm it — but Buffer::consume advances position and only shifts past capacity / 2, so retiring an 8-byte prefix moves neither capacity nor available_space(), which are the two quantities extract_messages' loop watches. The loop returns on the very iteration that consumed, one readable() short of the refill the re-arm just authorised. The re-arm lands with nothing left to use it.
So the fix needs a third termination anchor in extract_messages, checked first: a failed parse that retired bytes. It needs no spin guard — consume is the sole writer of position, every continue retires at least one byte, and the iteration count is bounded by what the peer wrote, which is the same bound the Ok arm has always had.
For the record, the #1436 anchor is strictly better on this input than the one it replaced — same malformed write, pending=16 after, against pending=24 under the old capacity-only anchor — so this issue is not a regression from that change.
Asked for
Re-arm Ready::READABLE on the error paths that leave the channel able to make progress, rather than only on NothingRead.
Corrected 2026-09-22 — two claims above are wrong and the implementation measured them so.
MessageTooLarge does not consume, and must not. Checked at 95dee167: that branch is a bare return Err(...) with no consume and no readiness bit. The bytes behind the header may be payload, and re-framing on them would decode peer-chosen bytes as a control-plane request. The buffer is therefore not on a frame boundary, refilling only re-parses the same header, and the frame can never complete anyway — a length above max_buffer_size does not fit a buffer bounded by max_buffer_size. It should not re-arm; doing so buys a busy loop, not a recovery. Only MessageLengthUnderDelimiter consumes, and it consumes exactly delimiter_size() bytes carrying a length no writer can emit for any payload.
InvalidProtobufMessage also belongs in the re-arm set, and this issue failed to name it. Since #1428 the whole frame is consumed before the decode error returns, so the buffer is left exactly as the decode-success path leaves it: frame lost, channel intact and framed on a boundary. Decide the set explicitly and state which errors re-arm and which do not, rather than re-arming unconditionally before the ?.
The regression test must be at the session level, not the channel level. For any claim about whether a session is schedulable, the unit of proof is a ClientSession driven through extract_messages — a channel-level test proves the channel re-syncs and says nothing about wants_to_tick. That distinction has now been the review finding twice on this file (#1438 F3 and #1436). Assert wants_to_tick(&client.channel) is true, or that the stranded bytes are delivered, after a malformed frame that leaves data in the socket.
See it red first: the test must fail against unmodified main.
Activity
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…