Skip to content

fix: SFTP download backpressure and binary transfer (#492)#493

Merged
billchurch merged 8 commits intomainfrom
fix/sftp-download-backpressure-binary
Mar 13, 2026
Merged

fix: SFTP download backpressure and binary transfer (#492)#493
billchurch merged 8 commits intomainfrom
fix/sftp-download-backpressure-binary

Conversation

@billchurch
Copy link
Copy Markdown
Owner

Summary

  • Extract shared backpressure module from terminal adapter into app/socket/backpressure.ts for reuse
  • Remove base64 encoding from SFTP download chunks — emit raw Buffer over Socket.IO (native binary support), eliminating 33% wire overhead and encode/decode CPU
  • Add backpressure control to SFTP download streaming — throttles chunk emission when WebSocket send buffer is full, keeping Socket.IO ping/pong heartbeats alive
  • Re-entrancy guard prevents concurrent emitBufferedChunks coroutines from racing on shared state (concurrency=32)
  • Cancellation cleanup ensures BackpressureController is destroyed when downloads are cancelled mid-transfer
  • Bump webssh2_client to ^3.6.0 for matching client-side binary chunk support

Fixes #492

Test plan

  • All 1346 server tests pass
  • All 216 client tests pass
  • Server lint, typecheck, and build clean
  • Client typecheck and build clean
  • Manual test: 100MB SFTP download succeeds
  • Manual test: 500MB SFTP download succeeds (previously failed at 300MB with ping timeout)
  • E2E Playwright tests pass

Fixes large file downloads (300MB+) causing 'ping timeout' disconnects
by throttling chunk emission when the WebSocket send buffer is full.

Resolves #492
- Add isEmitting flag to emitBufferedChunks to prevent concurrent coroutines from racing on nextChunkToEmit/chunkBuffer with DOWNLOAD_CONCURRENCY=32
- Store BackpressureController in a Map keyed by transferId so handleDownloadCancel can destroy it and unblock any pending drain wait
- Use config socketHighWaterMark value instead of hardcoded constant for backpressure high water mark
@billchurch billchurch merged commit ca88c95 into main Mar 13, 2026
3 of 5 checks passed
@billchurch billchurch deleted the fix/sftp-download-backpressure-binary branch March 13, 2026 17:02
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

[Bug]: Disconnected: Ping Timeout on large sftp downloads

1 participant