Skip to content

Commit

Permalink
[android][ios] Fix dispose problem with NativeHttpHandlers (#93262)
Browse files Browse the repository at this point in the history
#90298 made sure the MetricsHandler was the top level handler for all NativeHttpHandler requests similar to what is done with SocketsHttpHandler. After creating the MetricsHandler, the code mistakenly disposed of `_nativeHandler`, which resulted in `Dispose` being called multiple times and eventually throwing a `Cannot access a disposed object` exception.

Fixes #93252
  • Loading branch information
steveisok authored Oct 10, 2023
1 parent 53830e2 commit e2c319a
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ private HttpMessageHandler Handler
MetricsHandler metricsHandler = new MetricsHandler(handler, _nativeMeterFactory, out _);

// Ensure a single handler is used for all requests.
if (Interlocked.CompareExchange(ref _nativeMetricsHandler, metricsHandler, null) != null)
{
handler.Dispose();
}
Interlocked.CompareExchange(ref _nativeMetricsHandler, metricsHandler, null);
}

return _nativeMetricsHandler;
Expand Down Expand Up @@ -87,7 +84,7 @@ protected override void Dispose(bool disposing)

if (IsNativeHandlerEnabled)
{
_nativeHandler!.Dispose();
Handler.Dispose();
}
else
{
Expand Down

0 comments on commit e2c319a

Please sign in to comment.