Skip to content

Conversation

@dantraMSFT
Copy link
Contributor

Fix #7740

PR Summary

Fix the ObjectDisposedException in SSHClientSessionTransportManager.CloseConnection calling StreamWriter.Dispose multiple times.

There are two changes:

  • Clear the streamreader and streamwriter fields after disposing.
  • Use InterlockedExchange for the above fields and _sshProcessId to avoid possible race conditions for async usage.

PR Checklist

Fix possible race conditions accessing the fields during CloseConnection.
Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but this shouldn't be necessary. From Microsoft documentation:
"If an object's Dispose method is called more than once, the object must ignore all calls after the first one. The object must not throw an exception if its Dispose method is called multiple times. Instance methods other than Dispose can throw an ObjectDisposedException when resources are already disposed."

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iSazonov
Copy link
Collaborator

@TravisEz13 TravisEz13 merged commit 528d970 into PowerShell:master Sep 10, 2018
TravisEz13 pushed a commit that referenced this pull request Sep 10, 2018
…r fields are cleared after dispose. (#7746)

Fix possible race conditions accessing the fields during CloseConnection.
@TravisEz13 TravisEz13 added this to the v6.1.0 milestone Sep 10, 2018
@dantraMSFT dantraMSFT deleted the dantra/issue7740 branch September 10, 2018 20:41
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.

ObjectDisposedException attempting to Remove-PSSession an SSH-Based PSSession

5 participants