grpc client关闭连接后server报错 transport: connection EOF [triggered by remote service]
Describe the bug grpc客户端关闭连接后,会在server端报错
{"file":"http2_server.go:295","func":"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc.newHTTP2Server.func2","level":"error","msg":"KITEX: grpc server loopyWriter.run returning, error=rpc error: code = 1 desc = transport: connection EOF [triggered by remote service]","time":"2025-02-07T16:58:05.936997Z"}
看起来是跟https://github.com/cloudwego/kitex/pull/1556/files#diff-77fc1ea71b331d4a2ca56f9f7ee1b1963d433d6bed3d2355bdd9149f8d776765R1062 有关
client关闭连接时,走到这里 https://github.com/cloudwego/kitex/blob/develop/pkg/remote/trans/nphttp2/grpc/http2_server.go#L442
if err == io.EOF || err == io.ErrUnexpectedEOF || errors.Is(err, netpoll.ErrEOF) {
t.closeWithErr(errConnectionEOF)
return
}
https://github.com/cloudwego/kitex/blob/develop/pkg/remote/trans/nphttp2/grpc/http2_server.go#L1064
func (t *http2Server) closeWithErr(reason error) error {
t.mu.Lock()
if t.state == closing {
t.mu.Unlock()
return errors.New("transport: Close() was already called")
}
t.state = closing
streams := t.activeStreams
t.activeStreams = nil
t.mu.Unlock()
t.controlBuf.finish(reason)
close(t.done)
err := t.conn.Close()
1064行的t.controlBuf.finish(reason) 会把errConnectionEOF写入controlBuf的err字段,引发报错
To Reproduce
更新到kitext 0.12.1 或者 develop 分支
grpc客户端发起请求,然后关闭连接
或者使用grpcurl发送请求
grpcurl -plaintext 127.0.0.1:8888 foo
Expected behavior
正常关闭连接不引发err
Screenshots
Kitex version:
v0.12.1+ (最新的develop分支依然有此问题)
Environment:
The output of go env.
Additional context
Add any other context about the problem here.
@slowargo 感谢反馈! 请问你们当前的使用场景与交互模式(e.g. Unary, ServerStreaming...)是什么,client 主动使用短连接么?
@slowargo 感谢反馈! 请问你们当前的使用场景与交互模式(e.g. Unary, ServerStreaming...)是什么,client 主动使用短连接么?
Unary client 主动使用短连接
这个修复了吗