Skip to content

test(broker): accept a refusal that meets a closed socket - #84

Merged
bketelsen merged 1 commit into
mainfrom
irulan/broker-refusal-race
Nov 16, 2026
Merged

bketelsen merged 1 commit into
mainfrom
irulan/broker-refusal-race

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Summary

TestDevelopmentUIDNamesItsApp (from #81) fails under load with
write unix ...nats.sock: write: broken pipe, want an authorization violation.
It blocks make check, and so make bump.

Cause: nats.go writes CONNECT and PING in 2 writes (writeDirect). lodge
refuses a connection that it cannot name: it writes
-ERR 'Authorization Violation' and closes. When the close comes before the
PING write, the client fails with EPIPE (or ECONNRESET) and never reads the
refusal line. This is the same race as frostyard/hearth#4.

Fix (test only, no product change):

  • The new helper refusedUnnamed accepts the refusal text, or EPIPE or
    ECONNRESET. It accepts them only when the broker logged
    the broker refused a connection: lodge cannot name it. lodge writes that
    line before it closes. Any other error, or an admission, still fails.
  • The log check also closes a gap in the old test. With lodge's name check
    removed, the NATS server answers its own Authorization Violation for an
    account that it lacks, so the old text check still passed.

Other refusal tests in internal/broker:

  • TestBadTokenIsRefused and TestConnectNullIsRefused (client door) run over
    net.Pipe. A pipe write blocks until the peer reads, and refuse drains
    the peer's writes, so the refusal line always arrives.
  • TestConnectNullIsRefused (app socket) sends 1 write and reads the
    refusal line raw: no second write can meet the closed socket.
  • TestAppSocketClosesAnUnknownUID and the revoke tests accept any error.

Risk tier

Risk tier: 3, by the risk:high label. Matched path:
internal/broker/** (internal/broker/options_test.go). The change is safe:
it changes only a test file and adds a correction record. No product code
changes.

Verification

  • make check green (host).
  • make race and make cross green (host, in make ci).
  • make client-check, ui-check, shell-check: not run here. nsl
    fails on the agent host, and this PR changes nothing under client/, ui/
    or shell/. CI runs them.
  • Reproduced before the fix: 12 parallel runs of the race-built test
    binary (-test.count=200 -test.cpu 1,2,8) failed many times with
    broken pipe.
  • After the fix, the same load: 7200 runs, 0 failures. 429 of them took the
    EPIPE path.
  • go test -race -count=50 ./internal/broker/: ok (274 s).
  • Mutations, each with go test -race -count=50:
    • The AppEnabled check in serveApp's development branch removed:
      TestDevelopmentUIDNamesItsApp fails 50 of 50 (no refusal logged; the
      server answered its own authorization violation).
    • The refusal logged under another cause: fails 50 of 50.
    • The peer-uid check in serveApp removed: TestAppSocketClosesAnUnknownUID
      fails 50 of 50.
  • Guard and 1 record:
    .memory/corrections/2026-11-16-pr-84-refusal-tolerates-a-closed-socket.json.

nats.go writes CONNECT and PING in 2 writes. lodge refuses a connection
that it cannot name with -ERR 'Authorization Violation' and closes it, so
the PING write can fail with EPIPE before the client reads the refusal
line. TestDevelopmentUIDNamesItsApp then failed with a broken pipe under
load.

The test now accepts EPIPE or ECONNRESET as the refusal, and only
together with the broker's log line for that refusal. The log check also
closes a gap: the NATS server answers its own authorization violation for
an account that it lacks, so the old text check passed even when lodge
admitted the connection.
@github-actions github-actions Bot added level:L1 Read every line risk:high Touches a path in .github/risk-paths.json labels Nov 16, 2026
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Cross-review record

  • Reviewer: openai/gpt-6.1-sol. Coder: anthropic/claude-opus-5-5.
  • Base and merge-base: 6e89346a8cbcd000550d138ebcb61c6af4dcf014. Head: 553200f5fe8574c4b9852fc9ef5dfc349f71a883.
  • Scope: both changed files; context internal/broker/socket.go, the other refusal tests, and nats.go v1.55.0 sendConnect and writeDirect.
  • Result: Ready. Findings: none. Blocking: none.
  • Revert test: the fix is in the test itself, so mutations take its place. Each ran with go test -race -count=50 ./internal/broker/: the AppEnabled check removed (50 of 50 fail), the refusal logged under another cause (50 of 50 fail), and the peer-uid check removed (TestAppSocketClosesAnUnknownUID, 50 of 50 fail).
  • CI: all 9 checks green at the head above.

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 16, 2026
@bketelsen
bketelsen merged commit 16b6ff6 into main Nov 16, 2026
10 checks passed
@bketelsen
bketelsen deleted the irulan/broker-refusal-race branch November 16, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L1 Read every line ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a path in .github/risk-paths.json

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants