Skip to content

Ensure the SSHClientSessionTransportManager stream writer and reader fields are cleared after dispose. - #7746

Merged
Travis Plunk (TravisEz13) merged 1 commit into
PowerShell:masterfrom
dantraMSFT:dantra/issue7740
Sep 10, 2018
Merged

Travis Plunk (TravisEz13) merged 1 commit into
PowerShell:masterfrom
dantraMSFT:dantra/issue7740

Conversation

@dantraMSFT

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@iSazonov

Copy link
Copy Markdown
Collaborator

@TravisEz13
Travis Plunk (TravisEz13) merged commit 528d970 into PowerShell:master Sep 10, 2018
Travis Plunk (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 Travis Plunk (TravisEz13) added this to the v6.1.0 milestone Sep 10, 2018
@dantraMSFT
Dan Travison (dantraMSFT) deleted the dantra/issue7740 branch September 10, 2018 20:41
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…r fields are cleared after dispose. (PowerShell#7746)

Fix possible race conditions accessing the fields during CloseConnection.
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…r fields are cleared after dispose. (PowerShell#7746)

Fix possible race conditions accessing the fields during CloseConnection.
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