Skip to content

Commit 3b00579

Browse files
committed
fix"
1 parent df8aa56 commit 3b00579

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/InProcessTestHost/Sidecar/Dispatcher/WorkItemDispatcher.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ async Task ExecuteWorkItem(T workItem)
308308
// Execute the work item and wait for it to complete
309309
await this.ExecuteWorkItemAsync(workItem);
310310
}
311+
catch (OperationCanceledException)
312+
{
313+
// OperationCanceledException indicates the client has disconnected or the operation was canceled.
314+
// This is expected during shutdown or when tests are tearing down.
315+
await this.AbandonWorkItemAsync(workItem);
316+
}
311317
catch (Exception ex)
312318
{
313319
this.log.DispatchWorkItemFailure(

src/InProcessTestHost/Sidecar/Grpc/TaskHubGrpcServer.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,15 +834,20 @@ await this.SendWorkItemToClientAsync(new P.WorkItem
834834

835835
async Task SendWorkItemToClientAsync(P.WorkItem workItem)
836836
{
837-
IServerStreamWriter<P.WorkItem> outputStream;
837+
IServerStreamWriter<P.WorkItem>? outputStream;
838838

839839
// Use a lock to mitigate the race condition where we signal the dispatch host to start but haven't
840840
// yet saved a reference to the client response stream.
841841
lock (this.isConnectedSignal)
842842
{
843-
outputStream = this.workerToClientStream ??
844-
// CA2201: Use specific exception types
845-
throw new InvalidOperationException("TODO: No client is connected! Need to wait until a client connects before executing!");
843+
outputStream = this.workerToClientStream;
844+
}
845+
846+
// If no client is connected, throw OperationCanceledException so the dispatcher handles this gracefully.
847+
// This can happen during test teardown or when a client disconnects unexpectedly.
848+
if (outputStream == null)
849+
{
850+
throw new OperationCanceledException("No client is connected. The client may have disconnected.");
846851
}
847852

848853
// The gRPC channel can only handle one message at a time, so we need to serialize access to it.

0 commit comments

Comments
 (0)