Skip to content

Race Condition in ShellStream causing NullReferenceException #453

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

Closed
keithallenjackson opened this issue Aug 2, 2018 · 2 comments · Fixed by #1322
Closed

Race Condition in ShellStream causing NullReferenceException #453

keithallenjackson opened this issue Aug 2, 2018 · 2 comments · Fixed by #1322
Labels
Milestone

Comments

@keithallenjackson
Copy link

Issue:
Race condition in ShellStream occurs when underlying connection abruptly disconnects. The disconnect causes the stream to dispose. The Expect(Regex, TimeSpan) method utilizes an AutoResetEvent used to synchronize when new data is received, but the AutoResetEvent is disposed of and set to null.

Fix:
Do not dispose of an object that could be in use by another thread. In this particular context, the Producer (underlying connection) has abruptly finished, so the ShellStream would need have a state that reflects this. Any methods that utilize the existing (and only remaining) data, should not wait for more data to arrive and either return null (such as Expect) immediately, or throw SshConnectionException. The Consumer (user of the API) should be the one that disposes.

keithallenjackson pushed a commit to keithallenjackson/SSH.NET that referenced this issue Aug 18, 2018
+ ShellStream.Expect no longer throws NullReferenceException when channel unexpectedly disconnects.
+ Adds Disconnect event to ShellStream.
+ Adds Disposed property to ShellStream to read internal disposed state.
@drieseng drieseng added this to the 2020.0.0-beta2 milestone Jun 28, 2020
@drieseng drieseng modified the milestones: 2020.0.0, 2020.1.0 Dec 31, 2020
@IgorMilavec
Copy link
Collaborator

I have created a discussion #926 for all ShellStream related issues.

@WojciechNagorski
Copy link
Collaborator

This issue has been fixed in the 2024.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants