@@ -135,12 +135,12 @@ protected virtual bool DisconnectCore(CircuitHost circuitHost, string connection
135135 var result = ConnectedCircuits . TryRemove ( circuitId , out circuitHost ) ;
136136 Debug . Assert ( result , "This operation operates inside of a lock. We expect the previously inspected value to be still here." ) ;
137137
138- var previouslyConnected = circuitHost . SetDisconnected ( ) ;
138+ circuitHost . Client . SetDisconnected ( ) ;
139139 RegisterDisconnectedCircuit ( circuitHost ) ;
140140
141141 Log . CircuitMarkedDisconnected ( _logger , circuitId ) ;
142142
143- return previouslyConnected ;
143+ return true ;
144144 }
145145
146146 public void RegisterDisconnectedCircuit ( CircuitHost circuitHost )
@@ -309,13 +309,9 @@ private Task PauseAndDisposeCircuitEntry(DisconnectedCircuitEntry entry)
309309
310310 private async Task PauseAndDisposeCircuitHost ( CircuitHost circuitHost , bool saveStateToClient )
311311 {
312- if ( circuitHost . SetDisconnected ( ) )
313- {
314- await circuitHost . Renderer . Dispatcher . InvokeAsync ( ( ) => circuitHost . OnConnectionDownAsync ( default ) ) ;
315- }
316-
317312 await _circuitPersistenceManager . PauseCircuitAsync ( circuitHost , saveStateToClient ) ;
318313 circuitHost . UnhandledException -= CircuitHost_UnhandledException ;
314+ circuitHost . Client . SetDisconnected ( ) ;
319315 await circuitHost . DisposeAsync ( ) ;
320316 }
321317
@@ -381,12 +377,10 @@ private void DisposeTokenSource(DisconnectedCircuitEntry entry)
381377 }
382378
383379 // We don't expect this to throw. User code only runs inside DisposeAsync and that does its own error handling.
384- public async ValueTask TerminateAsync ( CircuitId circuitId )
380+ public ValueTask TerminateAsync ( CircuitId circuitId )
385381 {
386382 CircuitHost circuitHost ;
387383 DisconnectedCircuitEntry entry = default ;
388- var circuitHandlerTask = Task . CompletedTask ;
389-
390384 lock ( CircuitRegistryLock )
391385 {
392386 if ( ConnectedCircuits . TryGetValue ( circuitId , out circuitHost ) || DisconnectedCircuits . TryGetValue ( circuitId . Secret , out entry ) )
@@ -395,21 +389,17 @@ public async ValueTask TerminateAsync(CircuitId circuitId)
395389 DisconnectedCircuits . Remove ( circuitId . Secret ) ;
396390 ConnectedCircuits . TryRemove ( circuitId , out _ ) ;
397391 Log . CircuitDisconnectedPermanently ( _logger , circuitHost . CircuitId ) ;
398-
399- if ( circuitHost . SetDisconnected ( ) )
400- {
401- circuitHandlerTask = circuitHost . Renderer . Dispatcher . InvokeAsync ( ( ) => circuitHost . OnConnectionDownAsync ( default ) ) ;
402- }
392+ circuitHost . Client . SetDisconnected ( ) ;
403393 }
404394 }
405395
406- await circuitHandlerTask ;
407-
408396 if ( circuitHost != null )
409397 {
410398 circuitHost . UnhandledException -= CircuitHost_UnhandledException ;
411- await circuitHost . DisposeAsync ( ) ;
399+ return circuitHost . DisposeAsync ( ) ;
412400 }
401+
402+ return default ;
413403 }
414404
415405 // We don't need to do anything with the exception here, logging and sending exceptions to the client
0 commit comments