Skip to content

Don't dispose channel when completing SshCommand #1596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

Rob-Hague
Copy link
Collaborator

@Rob-Hague Rob-Hague commented Feb 5, 2025

The new(-ish) implementation of SshCommand has a race condition for short-lived commands where SSH_MSG_CHANNEL_CLOSE may be processed on the message loop thread before SSH_MSG_CHANNEL_SUCCESS is waited upon on the Execute (main) thread. This manifests in an ArgumentNull/NullReference exception on the wait handle because the channel has already been closed and disposed.

Fix this by delaying the channel dispose until the command dispose.

I wrote a test for this but it depended too much on implementation for my liking. The fix has been verified per #1557 (comment)

fixes #1557

The new(-ish) implementation of SshCommand has a race condition for short-lived
commands where SSH_MSG_CHANNEL_CLOSE may be processed on the message loop thread
before SSH_MSG_CHANNEL_SUCCESS is waited upon on the Execute (main) thread. This
manifests in an ArgumentNull/NullReference exception on the wait handle because
the channel has already been closed and disposed.

Fix this by only delaying the channel dispose until the command dispose.
@Rob-Hague Rob-Hague marked this pull request as ready for review February 16, 2025 16:58
@Rob-Hague Rob-Hague merged commit 99ef23c into sshnet:develop Feb 19, 2025
3 checks passed
@Rob-Hague Rob-Hague deleted the commandchannel branch February 19, 2025 12:16
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.

ArgumentNullException after upgrading from 2024.0.0 to 2024.0.1
2 participants