-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Bidi streaming leads to memory leak on the server side (CloseSend not called on the client side) #6457
Comments
Hi @mju, A memory leak is not expected in this scenario. We could take a better look if you could send us steps to reproduce this issue. Please let us know. |
This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
We have just discovered that this caused a goroutine leak as well. We accumulated 1500+ goroutines. |
When you close the What keepalive parameters do you set on your server? Also, there is a bug on the client where in we are failing to send a GOAWAY when the ClientConn is closed. See #460. Irrespective of this issue, if your server handler is blocked on |
This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
After more digging on our end, we identified a deadlock caused by hashicorp/vault#22393 on our server-side. As a result, for every request received by the server, two goroutines were leaked. It's two goroutines because of how gRPC's server.go works. We didn't configure keep-alive on the server-side. We started to reuse connections recently. We had a way to reproduce the problem quite reliably. What was confusing is that once CloseSend() was added, the leak stopped. Would you know why? It's as-if the locked-up goroutines on the server-side would be cleaned up when CloseSend() is present. We tried to find clues from server.go but weren't able to. In any case, the main cause of the leak was for sure the deadlock. Thanks for the help. |
Calling
Are you talking about |
This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
No, our server handler didn't block on Recv(). After the server handler got a response from the last Recv() call, it went and deadlocked. After adding CloseSend() on the client side, we no longer were able to reproduce the problem. It could somehow be a coincidence.
Correct. We didn't configure any of these. |
I cannot see any connection between |
This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
No. To confirm that fixing the deadlock alone fixed our problem, we tested it without |
Thanks. If you run into issues, please file a new issue. |
Hello there,
We had a memory leak on our gRPC server. The leaking handler was for a bidirectional streaming gRPC endpoint.
grpc-go/stream.go
Lines 141 to 156 in 02946a3
The user calls Close on the ClientConn.
We tried to close the ClientConn and tighten up the server by setting https://pkg.go.dev/google.golang.org/[email protected]/keepalive#ServerParameters. The server was still leaky with the following in the heap dump.The leak stopped as soon as we invoke CloseSend() on the client side after the last Send().
Here, I mainly want to get a clarification on whether CloseSend() is required so streaming won't be leaky on the server side?
I didn't find any documentation that suggests so. If so, maybe we can update some documents to suggest that.
If you can help, what was leaked? Was it also a goroutine + a context? How would you recommend that we configure our
servers so it's less prone to misbehaved clients?
Thanks a lot.
The text was updated successfully, but these errors were encountered: