Skip to content

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