Skip to content

RemoteAppClientOptions.BackchannelHandler should be a factory method #221

@duncansmart

Description

@duncansmart

I've called AddRemoteAppClient like so:

services.AddSystemWebAdapters()
    .AddRemoteAppClient(options =>
    {
        options.BackchannelHandler = new MyBackChannelHandler();
    }

Where BackChannelHandler is basically just a HttpClientHandler with some logging. But a few times during testing I've got an ObjectDisposedException: cannot access a disposed object. object name: 'SocketsHttpHandler'. in my HttpClientHandler's SendAsync:

image

(sorry for the screenshot, didn't grab the plain text)

On investigation It would appear that HttpClientHandler should be a new instance every time, otherwise you eventually hit this ObjectDisposedException. See dotnet/runtime#27610 for another example.

Therefore I suggest that RemoteAppClientOptions.BackchannelHandler be changed so that it's something like a Func<HttpMessageHandler> instead, so that AddRemoteAppClient can call it to get a new instance each time.

For example:

Change:

if (options.BackchannelHandler is { } handler)
{
    return handler;
}

To something like:

if (options.BackchannelHandlerFactory is { } factory)
{
    return factory();
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions