Skip to content

feat(q): connect_opts chooses the keepalive - #23

Merged
protocolstardust merged 1 commit into
RayforceDB:masterfrom
ihrfv:feat/q-connect-opts
Oct 26, 2026
Merged

protocolstardust merged 1 commit into
RayforceDB:masterfrom
ihrfv:feat/q-connect-opts

Conversation

@ihrfv

@ihrfv ihrfv commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Runs on what master already pins (core v3.0.1, rayforce-q 2.6.0); no submodule moves. One commit on top of 1.4.0.

What

  • QConnection::connect_opts(host, port, &ConnectOpts) opens a connection with the keepalive chosen. ConnectOpts holds user, password, timeout: Option<Duration> and keepalive
  • Keepalive is Auto (the core's 60 s default), Off, or Budget(Duration), the same three choices as the core's ray_ipc_connect_opts
  • connect and connect_with keep their signatures and get Auto, which is what q_connect already does, so no caller changes
  • rayforce-sys binds q_connect_opts and the Q_KEEPALIVE_AUTO / Q_KEEPALIVE_OFF constants

Why

rayforce-q 2.6.0 (RayforceDB/rayforce-q#24) added q_connect_opts, so a client can say how soon a silent peer counts as dead. The crate only reaches q_connect, which always picks Auto. A subscription that only receives, behind a VPN tunnel reaped without a FIN, is noticed about 60 s late on Auto and has no bound on unacknowledged data. A caller that needs it sooner has no safe way to ask for it.

Checks before the call

  • A zero timeout or budget is refused with a RayError::binding. The C side reads 0 as "no timeout" or "the default keepalive", the opposite of what a zero asks for. None and Off are how to say those
  • Anything past i32::MAX ms is refused, because the C side takes an int
  • A sub-millisecond value rounds up rather than truncating to that 0

Tests

Five in rayforce/tests/q.rs, against the mock Q server:

  • each keepalive variant connects and answers
  • a silent peer with a 200 ms timeout and a 30 s budget fails in well under 10 s. The timeout and the keepalive are both int ms at the C call, so if they were swapped this would still compile, and the test would wait out the budget instead
  • a zero budget, a budget past i32::MAX ms and a zero timeout are each refused before connecting

cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check and scripts/check-vendored-pin.sh pass locally on macOS. mkdocs build was not run.

Limits

  • On Linux the kernel acts on a probe tick, so a budget can fail up to one probe interval late. rayforce-q measured a 25 s budget failing at 28.3 s with the peer's packets dropped
  • A budget also sets TCP_USER_TIMEOUT, so a live peer that stops reading for that long fails the connection too

- QConnection::connect_opts takes ConnectOpts: credentials, a timeout
  and a Keepalive, which is Auto, Off or Budget(Duration), mirroring
  rayforce-q's q_connect_opts and the core's ray_ipc_connect_opts.
- connect and connect_with keep their signatures and get Auto, so no
  caller breaks.
- A zero timeout or budget is refused rather than passed on: the C side
  reads 0 as no timeout or as the default keepalive. Past i32::MAX ms is
  refused too, the most an int carries.
- The timeout and the keepalive are both int ms at the C call, so a test
  against a silent peer proves they are not swapped: swapped, it waits
  out the 30 s budget instead of the 200 ms timeout.
@protocolstardust

Copy link
Copy Markdown
Collaborator

Thanks Ihor, this is a really nice addition: it finally lets a caller say how soon a silent peer counts as dead, and the zero/overflow checks before the C call are exactly the kind of thing that saves a bad afternoon later.

Ran the workspace tests, clippy, fmt and the vendored-pin check locally on macOS, all green, and CI agrees. Merging.

@protocolstardust
protocolstardust merged commit 8dc8792 into RayforceDB:master Oct 26, 2026
2 checks passed
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