Skip to content

Commit 18d15e9

Browse files
committed
Ensure shutdown handler runs asynchronously.
1 parent 3f0a57a commit 18d15e9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Server/Handlers/ShutdownHandler.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ public class ShutdownHandler : IShutdownHandler
1313

1414
private readonly TaskCompletionSource<bool> _shutdownSource = new TaskCompletionSource<bool>(TaskContinuationOptions.LongRunning);
1515
public Task WasShutDown => _shutdownSource.Task;
16-
public Task Handle(object request, CancellationToken token)
16+
public async Task Handle(object request, CancellationToken token)
1717
{
18+
await Task.Yield(); // Ensure shutdown handler runs asynchronously.
19+
1820
ShutdownRequested = true;
19-
Shutdown?.Invoke(ShutdownRequested);
20-
_shutdownSource.SetResult(true); // after all event sinks were notified
21-
return Task.CompletedTask;
21+
try
22+
{
23+
Shutdown?.Invoke(ShutdownRequested);
24+
}
25+
finally
26+
{
27+
_shutdownSource.SetResult(true); // after all event sinks were notified
28+
}
2229
}
2330
}
2431
}

0 commit comments

Comments
 (0)