Repository navigation
fix(remote-ssh): recover from a closed cached SFTP subsystem - #3705
Merged
bobleer merged 2 commits intoNov 3, 2026
Merged
Conversation
Each connection caches one SFTP subsystem that every metadata query,
mutation and file operation reused. russh-sftp answers every request on a
closed subsystem channel with `UnexpectedBehavior("session closed")` and
never reopens it, while nothing marked that cache entry unusable. One
closed channel therefore failed every later file operation with
`Failed to stat '<path>': session closed` until the app restarted, even
though the SSH transport and every command channel kept working.
Retire the managed session when a request reports a stale transport, so
the manager opens a new subsystem channel on the same SSH transport
instead of serving the dead one. Idempotent metadata and existence
queries then replay once; mutations are never replayed, because a failed
request may already have reached the server, and instead leave the cache
healthy for the caller's next attempt. Open-based transfers already
retired on those errors, which is why only the plain queries stayed
stuck.
The regression test kills the channel of a cached session over an
in-memory SFTP transport and asserts that stat, exists and lstat recover
on a new subsystem channel. It fails on the previous code with
`Failed to stat '/file': session closed`.
Raing5Days
marked this pull request as ready for review
November 3, 2026 05:52
… channel A read or a recursive mkdir that was the first request after the cached subsystem closed still failed once: the dead session was retired, but the operation was not replayed. Read-only OPEN and mkdir_all (which accepts existing directories) are idempotent, so they now replay once on a new channel like stat, lstat and exists.
Collaborator
|
Reviewed against current I pushed 4f16b9d to close two remaining gaps in the same scenario:
The killable-channel test setup is factored into helpers, and two new tests cover these cases (both fail without the change). |
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.
Summary
Fixes
Failed to stat '<path>': session closed, which made the remote file browser unusable until OpenBitFun was restarted.Each SSH connection caches one SFTP subsystem. A cached session whose channel has closed keeps failing: russh-sftp answers every request on it with
UnexpectedBehavior("session closed")and never reopens the channel, and nothing marked that cache entry unusable. The bounded directory channel already retried on stale-transport errors andopen-based transfers already retired the session, butstat,lstat,existsand the plain mutation calls (create_dir,remove_file,remove_dir,rename,set_metadata) kept using the dead cache entry forever. The server side stayed healthy throughout and restarting the client cleared the in-memory cache, which matches the reported symptoms.Type and Areas
Type: bug fix
Areas: Rust core (
services-integrations, remote SSH)Motivation / Impact
ManagedSftpSessionnow retires itself when a request reports a stale transport, so the manager opens a new subsystem channel on the same SSH transport instead of serving the dead one.stat,lstat,exists) replay once on the fresh channel, so the file browser recovers inside the same operation instead of surfacing an error.log::warn!on the retry path.Verification
cargo fmt -p openbitfun-services-integrations- appliedcargo test --locked -p openbitfun-services-integrations --no-default-features --features remote-ssh-concrete --lib remote_ssh::- passed (190 passed, 0 failed, 5 ignored)cargo check --locked -p openbitfun-services-integrations --no-default-features- passeda_closed_subsystem_channel_is_replaced_instead_of_failing_foreverfails on the previous code withFailed to stat '/file': session closedand passes with the fix.Reviewer Notes
sftp_error_may_be_stale_transportalready classifies as transport failures (NoConnection,ConnectionLost,IO,Timeout,UnexpectedBehavior).Generated with OpenBitFun