Skip to content

Commit af9bc02

Browse files
committed
Catch non-observed exceptions on getting the disposed service in PauseCircuitAsync.
1 parent ea282bf commit af9bc02

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Components/Server/src/Circuits/CircuitRegistry.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,20 @@ private Task PauseAndDisposeCircuitEntry(DisconnectedCircuitEntry entry)
309309

310310
private async Task PauseAndDisposeCircuitHost(CircuitHost circuitHost, bool saveStateToClient)
311311
{
312-
await _circuitPersistenceManager.PauseCircuitAsync(circuitHost, saveStateToClient);
313-
circuitHost.UnhandledException -= CircuitHost_UnhandledException;
314-
await circuitHost.DisposeAsync();
312+
try
313+
{
314+
await _circuitPersistenceManager.PauseCircuitAsync(circuitHost, saveStateToClient);
315+
}
316+
catch (ObjectDisposedException ex)
317+
{
318+
// Expected when service provider is disposed during circuit cleanup e.g. by forced GC
319+
CircuitHost_UnhandledException(circuitHost, new UnhandledExceptionEventArgs(ex, isTerminating: true));
320+
}
321+
finally
322+
{
323+
circuitHost.UnhandledException -= CircuitHost_UnhandledException;
324+
await circuitHost.DisposeAsync();
325+
}
315326
}
316327

317328
internal async Task PauseCircuitAsync(

0 commit comments

Comments
 (0)