Fix: windowAdjust sends after CHANNEL_CLOSE#1483
Open
yurynix wants to merge 1 commit intomscdex:masterfrom
Open
Fix: windowAdjust sends after CHANNEL_CLOSE#1483yurynix wants to merge 1 commit intomscdex:masterfrom
yurynix wants to merge 1 commit intomscdex:masterfrom
Conversation
`windowAdjust()` in `lib/Channel.js` only guards against `outgoing.state === 'closed'` but not `'closing'`. After `close()` sets the state to `'closing'` and sends `SSH_MSG_CHANNEL_CLOSE` (message type 97), a pending `_read()` callback can still invoke `windowAdjust()`, which sends `SSH_MSG_CHANNEL_WINDOW_ADJUST` (message type 93) after `SSH_MSG_CHANNEL_CLOSE`. This violates RFC 4254 Section 5.3: > "Once a party has sent a CHANNEL_CLOSE message, it MUST NOT send further messages for the channel."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
Everything here (except this line) was written by Claude, however, I really have this problem in my project, and the solution really solves it, please consider it 🙃
Problem
windowAdjust()inlib/Channel.jsonly guards againstoutgoing.state === 'closed'but not'closing'. Afterclose()sets the state to'closing'and sendsSSH_MSG_CHANNEL_CLOSE(message type 97), a pending_read()callback can still invokewindowAdjust(), which sendsSSH_MSG_CHANNEL_WINDOW_ADJUST(message type 93) afterSSH_MSG_CHANNEL_CLOSE.This violates RFC 4254 Section 5.3:
The window between
close()and receiving the remote'sCHANNEL_CLOSEresponse leavesoutgoing.stateat'closing'— a state thatwindowAdjust()did not check.Fix
One-line change in
lib/Channel.js:280:Tests
test/test-channel-window-adjust.jscontains four test cases:closing state — Creates a mock channel with
outgoing.state = 'closing'and verifieswindowAdjust()does not callchannelWindowAdjust. This is the bug reproduction: it fails without the fix and passes with it.open state (sanity check) — Verifies
windowAdjust()works normally whenoutgoing.state = 'open', confirming the fix doesn't break the happy path.closed state — Verifies the existing guard against
outgoing.state = 'closed'still works.integration test — Sets up a real client/server connection via
setupSimple, executes a command, monkeypatcheschannelWindowAdjustto detect post-close calls, destroys the stream (triggeringclose()→'closing'), then manually invokes_read()to simulate a pending read callback. Asserts no window adjust was sent after close.