Skip to content

Fix race condition in get_free_port (#802)#825

Open
therohityadav wants to merge 1 commit intobitcoin-core:masterfrom
therohityadav:fix-get-free-port-race-condition
Open

Fix race condition in get_free_port (#802)#825
therohityadav wants to merge 1 commit intobitcoin-core:masterfrom
therohityadav:fix-get-free-port-race-condition

Conversation

@therohityadav
Copy link

Fixes #802

Problem

The get_free_port function was previously binding to "" (all interfaces). This caused a race condition where the OS would assign a port that appeared free on 0.0.0.0 but was actually unavailable or restricted when bitcoind specifically tried to bind to 127.0.0.1 milliseconds later.

Solution

I updated s.bind(("", 0)) to s.bind(("127.0.0.1", 0)).
This forces the OS to select a port specifically on the loopback interface ensuring it matches the interface bitcoind uses in the tests.

Verification

I verified locally that the function now returns a port explicitly bound to 127.0.0.1.

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.

get_free_port broken

1 participant