cloudwego / cloudwego/kitex

grpc client关闭连接后server报错 transport: connection EOF [triggered by remote service]

Open
#1,687 3 comments 0 reactions 1 assignee Assigned to @DMwangnima View on GitHub
Dominant language
Go
Stars
8k
Forks
918
Avg merge
1d 13h
Merged PRs (30d)
7

Description

**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**

![Image](https://github.com/user-attachments/assets/486f9233-72cf-4e8d-804e-d62aef85ee26)

![Image](https://github.com/user-attachments/assets/44fee104-06c0-44b3-b6ca-1fe87c2ea315)

**Kitex version:**

v0.12.1+
(最新的develop分支依然有此问题)

**Environment:**

The output of `go env`.

**Additional context**

Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.