fix: bound PTY output memory growth#30
Open
htazq wants to merge 1 commit into
Open
Conversation
This was referenced Jun 4, 2026
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.
Supersedes #27.
Summary
output_tx.send().await, which could allow russh/internal buffers to grow when frontend output stalls.reset(), and preserve backward compatibility whentabToGroupMapis absent during terminal group serialization.cargo fmtto the Rust workspace.Root Cause
The previous main-branch implementation and #27 both focused on bounding downstream WebSocket/frontend output. Real stress testing showed that blocking the PTY/WebSocket reader does not reliably bound process memory. When the downstream path stalls, the SSH channel reader can stop draining
channel.wait(), and output may still accumulate upstream inside russh/internal buffers.This PR moves the memory boundary closer to the SSH channel reader: the reader keeps draining remote output and drops overflow before it can accumulate in the SSH stack.
Validation
cargo fmt --checkcargo checkcargo test --lib— 77 passed, 7 ignoredtest_pty_output_memory_stays_bounded_when_output_is_not_consumedwith local Paramiko SSH server, 60s, max private-memory growth about 3.3 MBtest_websocket_pty_memory_stays_bounded_when_frontend_stallswith local Paramiko SSH server, 60s, 4 output frames / 149,504 bytes, max private-memory growth about 3.8 MBpnpm exec tsc --noEmitpnpm test— 406 passed, 7 skippedpnpm lint— 0 errors, existing warnings remainpnpm build