diff --git a/src/MagicOnion.Server/Hubs/StreamingHub.cs b/src/MagicOnion.Server/Hubs/StreamingHub.cs index cd0ead51a..2ef10b1fa 100644 --- a/src/MagicOnion.Server/Hubs/StreamingHub.cs +++ b/src/MagicOnion.Server/Hubs/StreamingHub.cs @@ -112,13 +112,15 @@ public async Task> Connect() // NOTE: If DuplexStreaming is disconnected by the client, IOException will be thrown. // However, such behavior is expected. the exception can be ignored. } - catch (IOException) + catch (Exception ex) when (ex is IOException or InvalidOperationException) { - // NOTE: If the connection closed with STREAM_RST, PipeReader throws an IOException. + var httpRequestLifetimeFeature = this.Context.CallContext.GetHttpContext()?.Features.Get(); + + // NOTE: If the connection is completed when a message is written, PipeWriter throws an InvalidOperationException. + // NOTE: If the connection is closed with STREAM_RST, PipeReader throws an IOException. // However, such behavior is expected. the exception can be ignored. // https://github.com/dotnet/aspnetcore/blob/v6.0.0/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs#L516-L523 - var httpRequestLifetimeFeature = this.Context.ServiceProvider.GetService()?.HttpContext?.Features.Get(); - if (httpRequestLifetimeFeature is null || !httpRequestLifetimeFeature.RequestAborted.IsCancellationRequested) + if (httpRequestLifetimeFeature is null || httpRequestLifetimeFeature.RequestAborted.IsCancellationRequested is false) { throw; }