Skip to content

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

Draft
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:address-in-use-fix-67
Draft

pyln-testing: replace ephemeral-port-reserve with a filesystem lock approach#9211
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:address-in-use-fix-67

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

using pytest-xdist the ephemeral-port-reserve approach would only ensure no port conflicts per pytest worker. There could still be race conditions where we get "address already in use".

This new filesystem approach should work across pytest workers

Changelog-None

…pproach

using pytest-xdist the ephemeral-port-reserve approach would only ensure no port conflicts
per pytest worker. There could still be race conditions where we get "address already in use".

This new filesystem approach should work across pytest workers

Changelog-None
@daywalker90 daywalker90 requested a review from cdecker as a code owner June 12, 2026 11:27
@daywalker90 daywalker90 marked this pull request as draft June 12, 2026 12:30
@cdecker

cdecker commented Jun 12, 2026

Copy link
Copy Markdown
Member

I don't quite get why it is necessary to keep a list of reserved ports at all. The idea is to have the OS itself track the reservations, and have them time out after the usual 30s - 60s cleanup timeout, after which the TIME_WAIT state on the socket expires, and the port goes back into the pool of available ports (i.e., bind with that specific port no longer needs SO_REUSEADDR set, and the random port selection may return it).

So unless we have a test that somehow assumes we have control over a port, while not actively bound to it, for prolonged periods (30s - 60s+) we should never need to materialize the list of reservations, even worse, the list of reservations may think it has control over a port, when the OS has already given that port to someone else. So the materialized port list may actually be causing collisions that are harder to debug. To me, a test that runs for longer than 30s and still expects to have exclusive control over a port is the bigger problem. Due to the port returning to the free-pool, and the OS being allowed to reassign it, the list reservation approach will never work I think.

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