Skip to content
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

fix: Close connections in gRPC server on shutdown #2089

Merged
merged 6 commits into from
Sep 27, 2023
Merged

fix: Close connections in gRPC server on shutdown #2089

merged 6 commits into from
Sep 27, 2023

Conversation

chubei
Copy link
Contributor

@chubei chubei commented Sep 26, 2023

No description provided.

@chubei chubei requested a review from Jesse-Bakker September 26, 2023 16:33
@Jesse-Bakker
Copy link
Contributor

What is the difference between using the custom AsyncWrite implementation and serve_with_shutdown?

@chubei
Copy link
Contributor Author

chubei commented Sep 26, 2023

AddrStream is not affected by the signal passed to serve_with_shutdown, which results in nasty bugs in live. After dozer is stopped, any connection to the stopped server is still alive and the HTTP requests over it are served. The client sees old data from last run.

Our custom implementation ShutdownAddrStream will close the connection (by calling AddrStream::pool_shutdown) when shutdown signal is received. And serve_with_shutdown will actually wait for connection being disconnected on shutdown, thus the shutdown is complete and graceful.

@Jesse-Bakker
Copy link
Contributor

Okay, I dove way too deep into the source code of tonic and hyper. The way we used to do it with an AbortHandle is definitely wrong, as you noticed, because hyper will spawn a new task for every connection and those tasks will just keep running.

serve_with_shutdown and serve_with_incoming_shutdown should (according to their implementation) gracefully shutdown connections (they pass a channel sender to the task and await the receiver closing) and only complete its future after all connections are drained. If that's not working, it's a bug in hyper.

@chubei
Copy link
Contributor Author

chubei commented Sep 26, 2023

It works correctly, but we can't wait for all connections to go down. We need to close the connection from server side.

@Jesse-Bakker
Copy link
Contributor

Alright, I get it now 👍

dozer-api/src/grpc/mod.rs Outdated Show resolved Hide resolved
dozer-api/src/grpc/mod.rs Outdated Show resolved Hide resolved
dozer-api/src/grpc/mod.rs Outdated Show resolved Hide resolved
@chubei chubei enabled auto-merge September 27, 2023 08:27
@chubei chubei added this pull request to the merge queue Sep 27, 2023
Merged via the queue into getdozer:main with commit 8296ead Sep 27, 2023
4 checks passed
@chubei chubei deleted the fix/shutdown branch September 27, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants