Skip to content

Handle race condition when HttpListener is stopped or closed#63394

Merged
wfurt merged 4 commits intodotnet:mainfrom
kevingosse:httplistener
Jan 5, 2022
Merged

Handle race condition when HttpListener is stopped or closed#63394
wfurt merged 4 commits intodotnet:mainfrom
kevingosse:httplistener

Conversation

@kevingosse
Copy link
Contributor

Fixes #63345

If the HttpListener is stopped or closed while GetContext is executing, the _currentSession field may be null. This PR detects this case and throws a HttpListenerException instead of a NullReferenceException.

@ghost ghost added area-System.Net.Http community-contribution Indicates that the PR has been added by a community member labels Jan 5, 2022
@ghost
Copy link

ghost commented Jan 5, 2022

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

Issue Details

Fixes #63345

If the HttpListener is stopped or closed while GetContext is executing, the _currentSession field may be null. This PR detects this case and throws a HttpListenerException instead of a NullReferenceException.

Author: kevingosse
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

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

The change seems reasonable to me.

I would expect BeginGetContext to have the same issue:

asyncResult = new ListenerAsyncResult(_currentSession!, state, callback);

Can you please add the null check there as well?

@kevingosse
Copy link
Contributor Author

Good catch, done in a48c5d9

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

@wfurt wfurt merged commit ec5471c into dotnet:main Jan 5, 2022
@karelz karelz added this to the 7.0.0 milestone Jan 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net.Http community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException when closing HttpListener

4 participants