Connection drops if keep-alive is enabled
Closed this issue · 2 comments
We decided to update our Unity project to use grpc-dotnet via YetAnotherHttpHandler
as recommended here. And everything worked as excepted until I decided to set Http2KeepAliveInterval
. When I launched the application, the connection simply dropped, and I could not find a reason why this could happen.
I'm not sure, but it might be a bug.
This is fragment of the code how I initialize a channel on the client side (I used new source generator to make a gRPC client):
var httpHandler = new YetAnotherHttpHandler
{
Http2KeepAliveTimeout = TimeSpan.FromMilliseconds(KeepAliveTimeoutMilliseconds),
Http2KeepAliveInterval = TimeSpan.FromMilliseconds(KeepAliveMilliseconds),
Http2Only = true,
SkipCertificateVerification = true,
};
// Initialize gRPC channel provider when the application is loaded.
GrpcChannelProviderHost.Initialize(new DefaultGrpcChannelProvider(() => new GrpcChannelOptions
{
HttpHandler = httpHandler,
}));
GrpcChannel = GrpcChannel.ForAddress($"https://{host}:{ApiSslPort}", new GrpcChannelOptions
{
HttpHandler = httpHandler,
});
var communicationService = MagicOnionClient.Create<ICommunicationService>(GrpcChannel, new IClientFilter[]
{
new GrpcExceptionInterceptor(loggerService)
});
This is how I configured Kestrel on the server side:
optionsSetup.Listen(IPAddress.Any, settings.CommunicationHttpsPort, listenOptions =>
{
listenOptions.UseHttps(options =>
{
var certificateGenerator = optionsSetup.ApplicationServices.GetRequiredService<TlsCertificatesGenerator>();
var logger = optionsSetup.ApplicationServices.GetRequiredService<ILogger<KestrelOptionsSetup>>();
options.ServerCertificateSelector = (context, _) =>
ServerCertificateSelector((IPEndPoint)context?.LocalEndPoint!, certificateGenerator, logger);
});
listenOptions.Protocols = HttpProtocols.Http2;
});
Attaching server side and Unity side logs with specified YAHA_ENABLE_DEBUG_TRACING
. I cut them a little to exclude product specific logs.
server-side-logs.log
unity-logs.log
I'm not sure if this will be useful, but I'll also attach a Wireshark dump with and without keepalive enabled.
with-keep-alive.csv
without-keep-alive.csv
Thank you for your very detailed report! We have just released 1.4.2, so please try that.
@mayuki Works as expected. Thanks!