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

pyln-testing: replace ephemeral-port-reserve with a filesystem lock approach

Public commit record

What the developer wrote

Authored by daywalker90

95/100 · Strong
pyln-testing: replace ephemeral-port-reserve with a filesystem lock approach

For some reason ports go back into the available pool sooner than what we would expect. I'm not sure why, but it clearly happens.
ephemeral_port_reserve puts them in TIME_WAIT, we can bind to them immediately because of SO_REUSEADDR set,
but then, probably because of node restarts, during a test the port is somehow returned
to a state where ephemeral_port_reserve will return it again immediately for another test.
So we need an additional mechanism for the ports to stay consistent during a test with node restarts.
Our current mechanism was flawed in combination with pytest-xdist since it was tracking per worker, not per machine.

This new filesystem approach should work across pytest workers

Changelog-None
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit fixes a flaky testing bug in Core Lightning's Python test helpers. When running many tests in parallel, the old code could accidentally reuse the same network port for two different test nodes, causing test failures or weird node-restart behavior. The fix switches to a file-based lock shared across all test workers on the same machine. It is a test-infrastructure reliability fix, not a fix for a user-facing security vulnerability.

Recommended action

No urgent action required. Treat as a normal test-framework reliability improvement. Reviewers may want to verify that `cleanup_stale_port_locks()` cannot be abused via symlink or stale PID reuse, though the impact is limited to the test environment and the lock directory is world-writable under `/tmp`.

Security signals we found

01

Race condition in port allocation logic (test-only)

02

Shared resource coordination fix across parallel workers

03

Best-effort cleanup of stale lockfiles with broad exception swallowing

Risk score

Why this scored 11/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 2/15
Confidence 3/10
Evidence quality 2/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.