Setting Session to blocking in Drop for SftpInnerDropWrapper is incompatible with async usage
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 566
- Forks
- 163
- Avg merge
- 4h 51m
- Merged PRs (30d)
- 2
Description
In Drop for SftpInnerDropWrapper we set the session to blocking before completing the drop. Presumably this is related to https://github.com/alexcrichton/ssh2-rs/issues/220 since in non-blocking mode libssh2_sftp_shutdown may return LIBSSH2_ERROR_EAGAIN when it calls _libssh2_channel_free. Since ssh2 does not implement an async client, blocking mode is necessary so that libssh2 retries until it is able to free the channel, otherwise memory associated with the channel will "leak" until libssh2_session_free is called when the session is dropped.
Unfortunately this means that the ssh2 crate cannot really be used in an async client because dropping the Sftp can block indefinitely.
Resolving this probably requires a similar solution to https://github.com/alexcrichton/ssh2-rs/issues/220 - expose a method for async clients to use for shutting down the SFTP channel. In fact, it looks like we already have that method:
https://github.com/alexcrichton/ssh2-rs/blob/40d7d18415324205a9ba7ddd1c08b9f0fade42ec/src/sftp.rs#L425-L462
Is there any reason then for Drop to set the session to blocking before calling libssh2_sftp_shutdown? It seems like it would be preferable to "leak" the channel memory until free is called on the session instead of unexpectedly blocking an event loop if the user forgets to call the shutdown method.
@wez do you have any thoughts on this? it looks like you and @Ten0 were the last ones to touch this part of the code in these PRs:
Thanks!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/sftp.rs at the SftpInnerDropWrapper Drop implementation around lines 503-517, then read the existing shutdown method around lines 425-462. Check how libssh2_sftp_shutdown behaves in non-blocking mode and how the earlier issue and linked pull requests informed the current blocking behavior. Done means the async-use tradeoff and shutdown behavior are resolved without unexpectedly blocking an event loop.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100