Skip to content

fix: bound PTY output memory growth#30

Open
htazq wants to merge 1 commit into
GOODBOY008:mainfrom
htazq:fix/pty-output-memory-bound
Open

fix: bound PTY output memory growth#30
htazq wants to merge 1 commit into
GOODBOY008:mainfrom
htazq:fix/pty-output-memory-bound

Conversation

@htazq

@htazq htazq commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Supersedes #27.

Summary

  • Keep the SSH channel output reader draining even when the downstream PTY output queue is full.
  • Drop overflow at the SSH output boundary with a bounded queue instead of blocking on output_tx.send().await, which could allow russh/internal buffers to grow when frontend output stalls.
  • Add ignored local stress tests for both direct PTY backpressure and the full WebSocket PTY stall path.
  • Add a local Paramiko SSH stress server used by those ignored tests.
  • Fix existing test blockers so the normal test suite can run cleanly: skip hard-coded SSH integration tests unless explicitly enabled, add missing xterm mock reset(), and preserve backward compatibility when tabToGroupMap is absent during terminal group serialization.
  • Apply cargo fmt to 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 --check
  • cargo check
  • cargo test --lib — 77 passed, 7 ignored
  • direct PTY stress: test_pty_output_memory_stays_bounded_when_output_is_not_consumed with local Paramiko SSH server, 60s, max private-memory growth about 3.3 MB
  • WebSocket PTY stall stress: test_websocket_pty_memory_stays_bounded_when_frontend_stalls with local Paramiko SSH server, 60s, 4 output frames / 149,504 bytes, max private-memory growth about 3.8 MB
  • pnpm exec tsc --noEmit
  • pnpm test — 406 passed, 7 skipped
  • pnpm lint — 0 errors, existing warnings remain
  • pnpm build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant