Skip to content

Comments

Dispose of ClientWebSocket when it fails to connect#47616

Merged
stephentoub merged 1 commit intodotnet:masterfrom
stephentoub:cwsdispose
Jan 29, 2021
Merged

Dispose of ClientWebSocket when it fails to connect#47616
stephentoub merged 1 commit intodotnet:masterfrom
stephentoub:cwsdispose

Conversation

@stephentoub
Copy link
Member

Somehow when it was ported to .NET Core, the transition from connecting to connected was switched to being done before the connect rather than after. As a result, if the connection fails and the websocket is never initialized, subsequent use (misuse) ends up null ref'ing. This restores the .NET Framework behavior, which was to dispose of the instance if the connect fails; subsequent operations then throw ObjectDisposedException.

Fixes #47582

Somehow when it was ported to .NET Core, the transition from connecting to connected was switched to being done before the connect rather than after.  As a result, if the connection fails and the websocket is never initialized, subsequent use (misuse) ends up null ref'ing.  This restores the .NET Framework behavior, which was to dispose of the instance if the connect fails; subsequent operations then throw ObjectDisposedException.
@ghost ghost added the area-System.Net label Jan 29, 2021
@ghost
Copy link

ghost commented Jan 29, 2021

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Somehow when it was ported to .NET Core, the transition from connecting to connected was switched to being done before the connect rather than after. As a result, if the connection fails and the websocket is never initialized, subsequent use (misuse) ends up null ref'ing. This restores the .NET Framework behavior, which was to dispose of the instance if the connect fails; subsequent operations then throw ObjectDisposedException.

Fixes #47582

Author: stephentoub
Assignees: -
Labels:

area-System.Net

Milestone: -

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM.

@stephentoub stephentoub merged commit 5fc6648 into dotnet:master Jan 29, 2021
@stephentoub stephentoub deleted the cwsdispose branch January 29, 2021 14:25
@ghost ghost locked as resolved and limited conversation to collaborators Feb 28, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undocumented NullReferenceException is Raised by ClientWebSocket.ReceiveAsync

3 participants