Skip to content

test(valkey): allocate refused port instead of hardcoding 12345 - #34412

Closed
robobun wants to merge 1 commit into
mainfrom
farm/0641063a/valkey-conn-failures-port
Closed

robobun wants to merge 1 commit into
mainfrom
farm/0641063a/valkey-conn-failures-port

Conversation

@robobun

@robobun robobun commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

What

test/js/valkey/reliability/connection-failures.test.ts went red in build 74111 on :debian: 13 x64 (4/4 retries on the shard, the other 19 shards for the same lane passed):

error: expect(received).toMatch(expected)
Expected substring or pattern: /connection closed|socket closed|failed to connect/i
Received: "Failed to read data (stack path)"

Cause

The suite hardcoded redis://localhost:12345 as a "guaranteed bad" address and asserted connection-refused behaviour. On that runner something was listening on TCP 12345, so RedisClient connected, wrote HELLO, read non-RESP bytes back, and the reply parser failed with Failed to read data (stack path) (the on_data stack-path error in src/runtime/valkey_jsc/valkey.rs) instead of the expected connection error.

Reproduced locally by binding a junk-writing TCP server to 12345 before driving the same code path:

Got error: "Failed to read data (stack path)"

Fix

Replace the fixed port with a bind(0) → read the port → close() sequence in beforeAll, the same pattern test/js/sql/wire-frames.ts exports as closedPort(). The connection-failure tests then target a freshly released ephemeral port on 127.0.0.1, independent of what else is bound on the machine.

The code paths exercised are unchanged: every affected test still drives RedisClient into on_connect_error/on_close and asserts the same /connection closed|socket closed|failed to connect/i messages and "Connection closed" snapshot.

Verification

With a garbage server deliberately bound to 12345:

[setup] evil server on 12345
[test] BAD_CONNECTION_URL = redis://127.0.0.1:46257
  PASS initial connection failure
  PASS offline queue enabled
  PASS clean up resources when disconnected
  PASS multiple clients not crash
4 pass, 0 fail

bun bd test test/js/valkey/reliability/connection-failures.test.ts passes (connection-failure cases are gated on Docker and skip in this container; the non-gated Auto-Reconnect In-Flight Commands case passes).

The connection-failures suite hardcoded redis://localhost:12345 as a
'guaranteed bad' address. On a CI runner where something else happened
to be listening on 12345, the RedisClient connected, sent HELLO, and
received non-RESP bytes back, so the tests failed with
'Failed to read data (stack path)' instead of the expected connection
error (seen in build 74111 on :debian: 13 x64, 4/4 retries).

Allocate a refused port with the bind(0)->close pattern already used
by test/js/sql/wire-frames.ts closedPort().
@robobun

robobun commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 5:07 PM PT - Jul 16th, 2026

❌ @robobun, your commit ec62f5d has 1 failures in Build #74142 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 34412

That installs a local version of the PR into your bun-34412 executable, so you can run:

bun-34412 --bun

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 27a49783-c300-46d4-84a8-951ada30e0ff

📥 Commits

Reviewing files that changed from the base of the PR and between 8c170f6 and ec62f5d.

📒 Files selected for processing (1)
  • test/js/valkey/reliability/connection-failures.test.ts

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

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only flake fix replacing a hardcoded port with the established bind(0)→close pattern.

What was reviewed:

  • Confirmed the inline logic is byte-identical to closedPort() in test/js/sql/wire-frames.ts.
  • net was already imported (used by the auto-reconnect suite below); beforeAll added to the bun:test import.
  • All BAD_CONNECTION_URL reads are inside test bodies in the same describe, so they run after beforeAll assigns it.
  • localhost → 127.0.0.1 matches the bind host, so no v4/v6 mismatch.
Extended reasoning...

Overview

Single-file, test-only change to test/js/valkey/reliability/connection-failures.test.ts. Replaces the hardcoded redis://localhost:12345 "refused" URL with a port allocated via net.createServer().listen(0) → read port → close() in a beforeAll, then builds redis://127.0.0.1:${port}. This is the same pattern already exported as closedPort() from test/js/sql/wire-frames.ts and used in sql-connect-error-reporting.test.ts and sql-onconnect-onclose-throw.test.ts.

Security risks

None. Test code only; binds to 127.0.0.1 on an ephemeral port and immediately closes. No runtime, auth, crypto, or network-facing production code is touched.

Level of scrutiny

Low. This is a CI flake fix with a well-documented root cause (something occupied TCP 12345 on one Debian shard, so RedisClient connected and failed at RESP parse instead of connect). The fix is mechanical and copies an established in-tree idiom line-for-line. The assertions in the affected tests are unchanged, so the test contract is preserved.

Other factors

  • net was already imported for the Auto-Reconnect In-Flight Commands block, so no new dependency.
  • BAD_CONNECTION_URL is declared with a definite-assignment assertion and only read inside test callbacks within the same describe, all of which execute after beforeAll — no TDZ/undefined risk.
  • Switching localhost → 127.0.0.1 aligns the connect target with the bind host, avoiding any IPv6-first resolution edge case.
  • The bug hunting system found no issues.

@robobun

robobun commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

Self-review: no concerns survived.

CI on build 74142: connection-failures.test.ts passed on every lane. The remaining reds are unrelated to this 12-line test-only change:

  • test/js/web/timers/timer-heap-race.test.ts (x64-asan): pre-existing ConcurrentTask leak on main, tracked in JSCTaskScheduler: drop deferred-work tasks scheduled after the event loop's last tick #34293
  • test/js/bun/util/password.test.ts (win x64-baseline): flaky RSS threshold, passed on retry
  • test/js/web/fetch/fetch-backpressure.test.ts (win x64): flaky, passed on retry
  • test/regression/issue/30205.test.ts (x64-asan): flaky, passed on retry
  • test/js/node/test/parallel/test-repl-close.js (win x64-baseline): flaky, passed on retry

Ready for review.

@robobun

robobun commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-07-16, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main.

@robobun robobun closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant