fix(huntsman): Use tokio::net::TcpListener to enable SO_REUSEADDR on gRPC servers. - #392
Merged
Merged
Conversation
Contributor
WalkthroughBoth scheduler and storage gRPC servers now explicitly bind TCP listeners, convert them to Tonic ChangesgRPC TCP listener serving
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
sitaowang1998
marked this pull request as ready for review
July 13, 2026 20:37
tokio::net::TcpListener to enable SO_REUSEADDR on gRPC servers.
LinZhihao-723
approved these changes
Jul 13, 2026
LinZhihao-723
left a comment
Member
There was a problem hiding this comment.
Directly modified the PR title. Notice that the scope should not be spider-grpc-server since we don't have any crates or namespaces of that name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Background
Tonic uses
std::net::TcpListenerby default, which does not setSO_REUSEADDRwhen opening the socket.TCP has a complicated state transition on close down. After a server actively closes its socket listening on a port, the port will enter a
TIME_WAITstate and timeout by default 60 seconds for the port to go back toCLOSEDstate. This is to ensure that stray/duplicate packet still on transmission will timeout on arrival and won't be delivered to newly connected listener.However, this 60-second wait is too long for a fast crash-recovered server. It tries to bind to a port in
TIME_WAIT, and fails ifSO_REUSEADDRis not set. It crashes again, and docker compose will restart it after exponential backoff. Thus, it is likely that the crashed server will only become healthy after 60 secondTIME_WAITtimeout + 40 second docker compose backoff, which is way too long for critical services like storage server and scheduler.Fix
This PR fixes the problem by using the
tokio::net::TcpListenerinstead ofstd::net::TcpListener, the default TCP listener used by tonic.std::net::TcpListenerdoes not setSO_REUSEADDR, while thetokio::net::TcpListenerhas it on.This PR:
grpc_server.rsin scheduler and storage, creates atokio::net::TcpListenerand pass it to tonic.Cargo.tomlin aforementioned components, addsnetfeature for tokio.Checklist
breaking change.
Validation performed
Summary by CodeRabbit