-
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
About client closing gRPC stream on receiving HTTP/2 GOAWAY #6232
Comments
Yes gRPC takes care of handling GOAWAY frames. You should not have to do anything from your client application to close the connection upon receipt of a GOAWAY frame.
There is an inherent race condition between the server sending GOAWAYs and the client creating new streams. Let's consider the following sequence of events:
Hope the above explanation helps.
No. |
Thank you for your detailed explanation! Now I understand how Then, how to gracefully close existings streams after
I've noticed that when closing streams in server-side streaming, the server should knew about when to stop on initial message, so server should close the stream. Ref: grpc/grpc#8023
But my server-side streaming rpc is intended to never finish (it is responsible for publishing and subscribing events when client is connected to the server, like chat server). The only situation when rpc is(should be) closed is when upstream host set changes and split-brain issue happens, so that server have to close dead rpc.
To conclude, I just want to gracefully close server-side streaming connection when needed (eg: max_connection_age, idle timeout, close_on_host_set_change, anything that sends |
Streams are closed when the server responds to a unary RPC and that response it received by the client. Or in the case of streaming RPCs, the stream on the server is closed when the server application returns from the RPC handler, and this is propagated to the client. The client can also initiate a close from its side by calling CloseSend as defined here: https://pkg.go.dev/google.golang.org/grpc#ClientStream
If you want to close the connection from the server-side, you can set the |
I'm already using grpc-go/internal/transport/http2_server.go Line 1173 in 47b3c55
Seems like in
So I also configured |
But that is working as intended, and the function and default values of each of those fields are clearly documented. Do you still think something is not working as documented? |
I think I misunderstood Then, since
So maybe I should return server-side streaming service function periodically?
For this method, is there any way to client get notified (I want to set client get notified on So my sole question is: is there any way to close connection associated with |
|
I'm actually using But I thought
I meant that I might have to use the methods you have mentioned earlier.
|
Graceful close of connections wait for existing streams to be closed before the connection is closed. If your server RPC handler never returns, then existing streams will not be closed, and therefore graceful connection close will not happen.
Please see https://github.com/grpc/proposal/blob/master/A9-server-side-conn-mgt.md for more details. |
Now I understand the full context of this issue.
Since my server-side streaming rpc never returns, there will be no "graceful close" of connection, so even when I might need to add timer in my rpc to perform graceful connection close when timer expires, combined with |
@krapie : It does look like this issue can be closed now. Please let us know if you have other open questions. Thanks. |
Hi, I'm currently searching for how to close connection when client receives HTTP/2
GOAWAY
, and I'm confused with how this actually works. So I'm leaving this question in gRPC-go. My questions may be opaque, so my apologies for my lack of knowledge.Context
I'm using gRPC server-side streaming, and I'm also using envoy for hash-based load balancing. But I've faced
split-brain
of gRPC stream(long-lived connection) when upstream host set changes. For more information, follow: envoyproxy/envoy#26459.I'm aware that I can set gRPC's
MAX_CONNECTION_AGE
to resolve this issue, Ref: Using gRPC for Long-lived and Streaming RPCs.Question
But how do I manage client to close connection on
GOAWAY
?I've searched for HTTP/2 GOAWAY RFC Spec and gRPC-go's
http2_server
withhttp2_client
codes. And these are what I understood:GOAWAY
to initiate shutdown of a connection, and client can decide to retry connection on receivingGOAWAY
.http2_server
in gRPC's transport layer sends twoGOAWAY
frames. with firstGOAWAY
with stream ID ofMaxUInt32
and secondGOAWAY
with last processed stream id.grpc-go/internal/transport/http2_server.go
Line 1364 in df82147
http2_client
receives these two frames and performs stream close when stream id is greater than thelast_stream_id
and smaller than the previouslast_stream_id
.grpc-go/internal/transport/http2_client.go
Line 1306 in df82147
I understood as gRPC is handling
GOAWAY
as HTTP/2 layer under in gRPC stacks, inhttp2_server
andhttp2_client
, but I'm confused about:http2_server
andhttp2_client
completely handlesGOAWAY
? Then I don't have to handleGOAWAY
and close connection manually?http2_server
andhttp2_client
completely handlesGOAWAY
, why this statement below does not become valid whenGOAWAY
is sent to close stream? e.g: If the stream id that I want to close is 5, then should id(last_stream_id) be smaller than 5? (which does not make sense becauselast_stream_id
will be 5, as last processed stream)grpc-go/internal/transport/http2_client.go
Line 1322 in df82147
Since
http2_client
is not closing stream connection even receivingGOAWAY
, I tried to capture HTTP/2 frames and close connection manually. But I don't see any APIs to get HTTP/2 frames.To summarize my questions:
GOAWAY
inhttp2_client
? (howlast_stream_id
should be set in order to close the stream?)GOAWAY
and reset(close) connection using gRPC go-sdk?If you are wondering why I'm trying to close stream manually, follow: yorkie-team/yorkie#526 for more contexts.
The text was updated successfully, but these errors were encountered: