Skip to content

System.Net.HttpListener.GetContext() throws HttpListenerException with ErrorCode=HttpStatusCode.InternalServerError on Linux after Stop() #123344

@inikulshin

Description

@inikulshin

Description

When System.Net.HttpListener.GetContext() is called after System.Net.HttpListener.Stop() on Linux, HttpListenerException with ErrorCode=HttpStatusCode.InternalServerError is thrown.

On Windows it's ErrorCode=SocketError.OperationAborted, and imo they should be aligned for all OSes.

Here is non-Windows code that throws:

if (_inGet && (exc is ObjectDisposedException))
_exception = new HttpListenerException((int)HttpStatusCode.InternalServerError, SR.net_listener_close);

Reproduction Steps

.

Expected behavior

Same HttpListenerException.ExitCode on all OSes or System.InvalidOperationException, as API declares:

https://learn.microsoft.com/en-us/dotnet/api/system.net.httplistener.getcontext?view=net-10.0#exceptions

InvalidOperationException
This object has not been started or is currently stopped.

Actual behavior

When System.Net.HttpListener.GetContext() is called after System.Net.HttpListener.Stop() on Linux, HttpListenerException with ErrorCode=HttpStatusCode.InternalServerError is thrown.

On Windows it's ErrorCode=SocketError.OperationAborted.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions