Skip to content

fix: hold assigned port at start-up until Pg start command exec - #252

Open
tzemanovic wants to merge 3 commits into
theseus-rs:mainfrom
tzemanovic:tomas/start-port-race
Open

tzemanovic wants to merge 3 commits into
theseus-rs:mainfrom
tzemanovic:tomas/start-port-race

Conversation

@tzemanovic

@tzemanovic tzemanovic commented Jul 20, 2026 •

Copy link
Copy Markdown

Hi,

Thanks for this crate! I'm using multiple embedded DBs concurrently with auto-assigned ports and it seems that there is a race condition in the start-up as randomly they fail to start. I found that the assigned port at start-up is not held open before the pg_ctl command uses it again, so another process may try re-use it in the meantime.

This fix instead tries to assign a random port directly for the pg_ctl command and retry 3 times on port conflict

@brianheineman

Copy link
Copy Markdown
Contributor

Hello @tzemanovic, thank you for the pull request. Instead of randomly assigning the port, my preference would be to get an ephemeral port from the OS and add support for retrying (with a configurable retry) when a port bind failure occurs.

@tzemanovic
tzemanovic force-pushed the tomas/start-port-race branch from 2e0b652 to 7fdd160 Compare September 15, 2026 09:43
@tzemanovic
tzemanovic force-pushed the tomas/start-port-race branch from 7fdd160 to 7a1802a Compare September 15, 2026 09:44
@tzemanovic

Copy link
Copy Markdown
Author

Hello @tzemanovic, thank you for the pull request. Instead of randomly assigning the port, my preference would be to get an ephemeral port from the OS and add support for retrying (with a configurable retry) when a port bind failure occurs.

I've made the changes, thanks @brianheineman !

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