-
-
Notifications
You must be signed in to change notification settings - Fork 947
Fixes for ShellStream.Expect, ShellStream.Read, ShellStream.Write, and NullReferenceExceptions. #458
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
Conversation
+ 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.
This is great, thank you. |
b216f41
to
2830ba9
Compare
/// <summary> | ||
/// Whether the instance is disposed. | ||
/// </summary> | ||
public bool Disposed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not expose this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm not a fan of exposing the "Disposed" state of an object (the User API should have complete control of that), this was added to check for a disposed state since an unexpected channel closure could cause the ShellStream to Dispose without explicit user API calls. Should I change the event handler for _channel disconect to not Dispose the ShellStream? Essentially, an abrupt channel closure puts the ShellStream in a 'half-used'/'half-disposed' state. Let me know your thoughts.
src/Renci.SshNet/ShellStream.cs
Outdated
@@ -550,6 +575,9 @@ public string Expect(Regex regex, TimeSpan timeout) | |||
{ | |||
var text = string.Empty; | |||
|
|||
// Flush the write buffer in case expecting output from previous write. | |||
if (!_isDisposed) Flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not something to change as part of this PR, but shouldn't we throw an ObjectDisposedException here (and consider the same for a few other methods) when the channel is closed or the ShellStream is disposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes back to the "half-used"/"half-Disposed" issue when an abrupt channel closure causes the ShellStream to abruptly be in a Disposed state without explicit user interaction. Under normal API usage, I agree 100% - Disposed state should be private, calling methods on a Disposed object should throw an ObjectDisposedException, and all of this behavior is appropriate because it is up to the user to set the 'disposed' state alone. Essentially, the user caused the Disposal, so therefore should know better than to use an object he/she disposed.
In this object, that behavior is not present. Maybe I should make a new private variable that specifies if the ShellStream is in a 'half-open' state? If so, how should the Write methods behave under this state? I'm genuinely curious about your thoughts. Thanks!
…l talking it through)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All that's left to discuss is the behavior of Dispose and abrupt channel closure.
How about this: States
Additions
|
Quick and incomplete feedback:
|
…isconnected Temporary fix until this is fixed upstream: sshnet#424 (comment) sshnet#458
Got busy with work and completely forgot about this. This is so out of date, there is no reason to keep it around. I'm closing. |
Adds tests (reproducing the issues) and code fixes for issues #454, #453, #432, #424, #180, #444, #301, #302.