Skip to content

Commit

Permalink
Merge pull request Cysharp#475 from Cysharp/hotfix/IgnoreStreamRstOnS…
Browse files Browse the repository at this point in the history
…treamingHub

Ignore exception on disconnection by STREAM_RST
  • Loading branch information
mayuki authored Nov 24, 2021
2 parents ef515a5 + d5d4bba commit 5205adf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/MagicOnion.Server/Hubs/StreamingHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -109,6 +112,17 @@ public async Task<DuplexStreamingResult<byte[], byte[]>> 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<IHttpContextAccessor>()?.HttpContext.Features.Get<IHttpRequestLifetimeFeature>();
if (httpRequestLifetimeFeature is null || httpRequestLifetimeFeature.RequestAborted.IsCancellationRequested)
{
throw;
}
}
finally
{
Context.CompleteStreamingHub();
Expand Down

0 comments on commit 5205adf

Please sign in to comment.