Skip to content

SSH transport: bound the shell/exec/SFTP request reply wait and keep early channel data #1767

Backlog

Description

@smart-ssh-planner

Goal

A server that never answers a shell, exec or SFTP subsystem request no longer blocks the connection forever, and output or an exit status that arrives before the reply is not lost.

Context

Follow-up of #1665 (PR #1675): the review noticed two gaps in the shared request-reply wait.

  • wait_for_request_reply (crates/ssh-transport/src/transport.rs:150-158) skips every message except Success/Failure/Close/Eof (Some(_) => continue). Data or an exit status sent before the reply is discarded.
  • The wait has no time limit. It is used by open_shell (~line 316) and the exec open path (~line 488); open_sftp has its own wait loop (~line 366) with the same two gaps. A server that never replies hangs the caller.
    OpenSSH and Dropbear send the reply first, so this is a robustness gap against unusual servers, not a current regression. Spec 0005 §4.1/§4.4 describe the refusal behaviour.

Requirements

  • Messages that arrive before the reply (Data, ExtendedData, ExitStatus, ExitSignal) are buffered and handed to the channel consumer after the reply is Accepted, in order.
  • The reply wait has a time limit (default 30 s, a named constant). On expiry the call fails with the existing SessionClosed-style error that fits a timeout, with no new error code unless needed; if a new code is needed it is added to the error table, the frontend code list and all locales.
  • open_sftp uses the same helper (or the same limit and buffering).
  • A refused or closed reply still never yields a working channel.

Acceptance Criteria

  • Unit test with the scripted ReplySource: Data, then ExitStatus, then Success returns Accepted and the buffered messages are available in order.
  • Unit test: no reply within the limit returns a timeout error (tokio paused time, no real wait).
  • Unit test: Failure after buffered data still gives Refused; Close before the reply still gives Closed.
  • open_shell, exec and open_sftp fail with an error, not a hang, against a server that never replies (in-process test server case).
  • Existing request_reply_tests and real-server tests stay green
  • Relevant automated tests pass

Technical Notes

Affected: crates/ssh-transport/src/transport.rs, in-process test server crates/ssh-transport/tests/fixtures/test_server.rs. The change only waits and buffers, so it adds no new path to a server; the filter engine and approval flow are untouched. Update spec 0005 if a timeout error text becomes visible. Add a changelog fragment only if the user-visible failure text changes.

Files: crates/ssh-transport/src/transport.rs, crates/ssh-transport/tests/fixtures/test_server.rs, crates/ssh-transport/tests/sudo_password.rs, docs/specs/0005-ssh-module.md

Spec impact: update 0005

Open questions

  • Replay mechanism: buffer in a Vec<ChannelMsg> that the consumers drain first (recommended), or a wrapper channel type. Choose the smaller diff.
  • Timeout value: 30 s recommended; make it a constant, not a setting.

Related Work

Activity

  1. added
    follow-up
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upssh

    Type

    Fields

    Priority

    P3 - Low

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions