AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 23 Bitcoin

rpctest: scope shared state to the current process

Public commit record

What the developer wrote

Authored by Calvin Kim

88/100 · Strong
rpctest: scope shared state to the current process

Two pieces of rpctest's global state silently aliased across concurrent
test processes (which is what `go test ./...` does by default, so any
`make unit` that exercises -tags=rpctest hit this):

- btcdExecutablePath compiled to a fixed path /tmp/btcd/rpctest/btcd.
Two `go build` invocations would race on the same file, occasionally
yielding a truncated or stale binary and downstream "tls: certificate
signed by unknown authority" failures when the harness tried to talk
to the resulting node.

- lastPort started at the same defaultNodePort in every process. The
bind-test in NextAvailablePort closes the listener before returning,
so two processes climbing from the same base would frequently hand
out the same port and one harness would die with "connection refused"
when btcd failed to bind.

Suffix the executable with a random uint32 and seed lastPort with a
random offset into a 50k-port window so each process climbs through
its own range.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a test-only reliability bug, not a security vulnerability. When running btcd's integration tests in parallel, two test processes were accidentally sharing the same temporary file path and the same starting port number. That caused random test failures: one process could overwrite the other's freshly built test binary, or two processes could try to use the same network port. The fix gives each test process its own random file name and a random starting port range. It does not change anything in the live Bitcoin node software end users run.

Recommended action

No production security action required. Developers running parallel tests with `-tags=rpctest` should update to this commit to eliminate flaky test failures. If backporting, include only the test harness changes; no node runtime changes are needed.

Security signals we found

01

Race condition on shared temporary executable path

02

Race condition on shared ephemeral port allocation

03

Test-only code path; no production node behavior affected

04

Symptoms included TLS certificate errors and connection refused failures during parallel test runs

05

Fix uses process-scoped randomization rather than synchronization

Risk score

Why this scored 23/100

Our methodology →
Potential impact 4/30
Exploitability 0/25
Stealth signal 2/15
Affected reach 3/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.