Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore exception on disconnection by STREAM_RST #475

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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