Skip to content

Preserve SFTP state when nonblocking shutdown would block - #370

Merged
yodaldevoid merged 1 commit into
rust-lang:masterfrom
omrzk:fix/nonblocking-sftp-shutdown-368
Oct 29, 2026
Merged

yodaldevoid merged 1 commit into
rust-lang:masterfrom
omrzk:fix/nonblocking-sftp-shutdown-368

Conversation

@omrzk

@omrzk omrzk commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Sftp::shutdown removes its inner state before calling libssh2. When nonblocking shutdown returns EAGAIN, the next call returns BAD_USE and the native resource can no longer be cleaned up through the wrapper.

Keep the uniquely held inner state until the native shutdown finishes. EAGAIN preserves both the retry path and the existing blocking destructor; completed shutdown still disables cleanup, and open files still prevent shutdown. Fixes #368.

The regression uses a loopback TCP proxy that pauses SSH server replies, so two successive shutdown attempts must return EAGAIN. It then releases the replies, completes shutdown, checks repeated shutdown returns BAD_USE, and opens another SFTP channel. A second test covers the open-file guard.

Validation with a local OpenSSH fixture:

  • The regression fails on the original code (BAD_USE on the second attempt) and passes with the fix.
  • Default and vendored-OpenSSL configurations each pass 31 integration tests and 10 doctests, with two PTY tests excluded. The full suite fails those same two tests on clean master because this unprivileged SSH daemon cannot write login records; no full passing-suite claim is made.
  • Default all-targets build, 1,009 ABI tests, rustfmt for the modified files, and diff checks pass. Default builds use headers/libraries from a local OpenSSL build because system development packages are absent.
  • Clippy was attempted and fails existing diagnostics on both this branch and clean master, including raw-pointer public APIs and existing warning-denied code.

@yodaldevoid

Copy link
Copy Markdown
Collaborator

Thank you for the PR!

@yodaldevoid
yodaldevoid merged commit 60b9c19 into rust-lang:master Oct 29, 2026
9 of 12 checks passed
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.

Sftp::shutdown loses its state when nonblocking shutdown returns EAGAIN

2 participants