Skip to content

test(rpc,graphql,serve): bind port 0 and read the bound address, ending the port race - #76

Merged
CryptoJones merged 1 commit into
mainfrom
fix/test-port-race-rpc-graphql-serve
Oct 24, 2026
Merged

CryptoJones merged 1 commit into
mainfrom
fix/test-port-race-rpc-graphql-serve

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

Cause

The scylla-rpc, scylla-graphql and scylla-serve integration tests picked a "free" port by binding 127.0.0.1:0, reading the port, and dropping the listener. Then they started the server on that port. Between the drop and the server's bind, a parallel test's server could take the same port, and the test would end up talking to the wrong server. That is how scylla-rpc/tests/remote.rs connection_cap_refuses_the_surplus_connection failed on main: it reached an uncapped server from another test and got success where it expected a refusal.

Fix

This is the same fix #74 made for scylla-http: start the server on port 0, so the OS hands it a port nothing else holds, and read the address it actually bound from its startup line.

  • scylla-rpc: scylla-rpc-serve already printed listener.local_addr(), so the binary is unchanged. A new tests/common/mod.rs spawn_server(envs) starts it on 127.0.0.1:0 and parses the address from the stderr startup line. It keeps draining stderr in a thread and returns (Server, addr). remote.rs, conformance.rs and tls.rs now use it. The same env vars are still passed: the token, SCYLLA_RPC_MAX_CONN, SCYLLA_RPC_HANDSHAKE_SEC, and the TLS cert/key paths.
  • scylla-graphql: the binary now announces server.server_addr().to_ip() (the bound address) in place of the requested one. The message wording is unchanged. A matching tests/common helper is used by api.rs (which still passes SCYLLA_GRAPHQL_TOKEN) and by conformance.rs.
  • scylla-serve: the binary now prints listener.local_addr()'s port in place of the requested one. Wording is unchanged, and the line still goes to stdout. The tests/common helper passes port 0, reads the address from stdout, and serve.rs's get/wait_ready now take that address.

Every per-file free_port() and duplicated Server guard is deleted. Test semantics are unchanged.

Ran

  • cargo fmt --all
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test --workspace --locked: all pass
  • cargo test -p scylla-rpc -p scylla-graphql -p scylla-serve --locked, 4 runs in a row: all pass

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

🤖 Generated with Claude Code

https://claude.ai/code/session_01JMTyE9inRv7Knv6jkmgDZs

…ng the port race

The scylla-rpc, scylla-graphql and scylla-serve tests picked a free port,
released it, then passed it to the server. A parallel test's server could take
the port first and answer in its place: connection_cap_refuses_the_surplus_connection
then reached an uncapped server and got success where it expected a refusal.

scylla-graphql and scylla-serve now announce the address they actually bound,
so port 0 works (scylla-rpc-serve already printed listener.local_addr()). Each
crate gets a shared tests/common helper that starts the server on port 0 and
reads the address from its startup line, the same way #74 fixed scylla-http.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JMTyE9inRv7Knv6jkmgDZs
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e5d5b256-67cc-481b-8e31-6c4ce3f96b4a
Commits

Reviewing files that changed from the base of the PR and between d07ca7e and 57dc004.

Files selected for processing: 11
  • crates/scylla-graphql/src/main.rs
  • crates/scylla-graphql/tests/api.rs
  • crates/scylla-graphql/tests/common/mod.rs
  • crates/scylla-graphql/tests/conformance.rs
  • crates/scylla-rpc/tests/common/mod.rs
  • crates/scylla-rpc/tests/conformance.rs
  • crates/scylla-rpc/tests/remote.rs
  • crates/scylla-rpc/tests/tls.rs
  • crates/scylla-serve/src/main.rs
  • crates/scylla-serve/tests/common/mod.rs
  • crates/scylla-serve/tests/serve.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CryptoJones
CryptoJones merged commit 955ec61 into main Oct 24, 2026
3 checks passed
@CryptoJones
CryptoJones deleted the fix/test-port-race-rpc-graphql-serve branch October 24, 2026 19:12
CryptoJones added a commit that referenced this pull request Oct 24, 2026
…slot (#77)

connection_cap_refuses_the_surplus_connection still failed on main after #76.
The port race was gone; this failure was a second race inside the test. The
readiness client's slot is freed asynchronously on the server, so the raw "hog"
connection could arrive while that slot was still counted. The server then
refused the hog itself, and the "surplus" client got the free slot and
succeeded.

The test now checks that the hog really holds the slot before it tries the
surplus client. A refused hog reads EOF; a hog holding the slot reads nothing,
because the server is waiting for its handshake. The test reconnects until the
hog holds the slot. This replaces the fixed 500 ms sleep.


Claude-Session: https://claude.ai/code/session_01JMTyE9inRv7Knv6jkmgDZs

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant