微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当流调用循环很大时,Grpc 双向流被对等端终止?

如何解决当流调用循环很大时,Grpc 双向流被对等端终止?

我在客户端 (dart) 和服务器 (.net) 之间有双向流。客户端有大流调用循环时出现问题

在服务器上我得到

System.IO.IOException: The request stream was aborted.
---> Microsoft.AspNetCore.Connections.ConnectionAbortedException: The HTTP/2 connection faulted.
  --- End of inner exception stack trace ---
  at system.io.pipelines.PipeCompletion.ThrowLatchedException()
  at system.io.pipelines.Pipe.GetReadResult(ReadResult& result)
  at system.io.pipelines.Pipe.GetReadAsyncResult()
  at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2MessageBody.ReadAsync(CancellationToken cancellationToken)
  at Grpc.AspNetCore.Server.Internal.PipeExtensions.ReadStreamMessageAsync[T](PipeReader input,HttpContextServerCallContext serverCallContext,Func`2 deserializer,CancellationToken cancellationToken)

在客户端我得到

gRPC Error (code: 2,codeName: UNKNowN,message: HTTP/2 error: Stream error: Stream was terminated by peer (errorCode: 2).,details: null)

它在小流调用循环时工作。

我试图增加 MaxStreamsPerConnection 但仍然没有工作

.ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureKestrel(serveroption => {
        
                        serveroption.Limits.Http2.MaxStreamsPerConnection = 5000;
                    }).UseStartup<Startup>();
                });

解决方法

我的应用程序使用 nginx 作为反向代理。原来是 nginx 网络服务器的问题。 我从 nginx 得到的错误

client intended to send too large chunked body: 10489464 bytes while sending request to upstream,

要解决这个问题,只需添加

http {
    ...
    client_max_body_size 20M;
}   

Nginx error: client intended to send too large body

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。