diff --git a/src/MagicOnion.Server/Hubs/StreamingHub.cs b/src/MagicOnion.Server/Hubs/StreamingHub.cs index a861dd69c..51a39ed26 100644 --- a/src/MagicOnion.Server/Hubs/StreamingHub.cs +++ b/src/MagicOnion.Server/Hubs/StreamingHub.cs @@ -5,6 +5,9 @@ using System.Threading.Tasks; using MagicOnion.Utils; using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Http.Features; namespace MagicOnion.Server.Hubs { @@ -109,6 +112,17 @@ 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 ex) + { + // NOTE: If the connection 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) + { + throw; + } + } finally { Context.CompleteStreamingHub();