Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: ensure embedded-postgres state is wiped between retries#20809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
zedkipp merged 1 commit intomainfromzedkipp/testserver-retry-state
Nov 21, 2025

Conversation

@zedkipp
Copy link
Contributor

@zedkippzedkipp commentedNov 17, 2025
edited
Loading

Retries were previously added when starting embedded postgres to mitigate port allocation conflicts (we can't use an ephemeral port for tests). Retries alone seemingly did not fix the test flakes. A new failure mode appeared on the retries: timing out connecting to the database.

When a port discovery error occurrs, embedded-postgres does not create the database. If the data directory exists on the next attempt, embedded-postgres will assume the database has already been created. This seems to cause the timeout error. Wipe all state between retries to ensure attempts execute the same logic that creates the database.

#658

This isn't easily testable or reproducible. That said, I tested this on a Linux machine by removing thetesting.Testing() call that enables the retries, hard-coding the initial postgres port and usingnc to force a port conflict.

@Emyrk
Copy link
Member

Could this accidentally delete real postgres data?

@zedkipp
Copy link
ContributorAuthor

@Emyrk I don't think so because the retries are only attempted when running tests.

coder/cli/server.go

Lines 2148 to 2149 ina272843

_,err=cfg.PostgresPort().Read()
retryPortDiscovery:=errors.Is(err,os.ErrNotExist)&&testing.Testing()

Emyrk reacted with thumbs up emoji

@zedkippzedkipp marked this pull request as ready for reviewNovember 17, 2025 20:56
@cstyan
Copy link
Contributor

To Steven's question/your answer, I still think it would be a good idea to leave apotential footgun comment on the assignment of the value forretryPortDiscovery to make it clear that if the assignment logic is changed to not includetesting.Testing() then we should also update the conditional check on the new block you've added.

Alternatively we could preemptively guard against that case by checking fortesting.Testing() on your block as well, or maybe slightly more involved but refactor so that the retry function is definable on the server struct and define the server within tests to have a retry function that does the filesystem cleaning.

I think the former (comment or add the additional check fortesting.Testing()) is enough for now to see if that resolves the flakiness.

Retries were previously added when starting embedded postgres to mitigate portallocation conflicts (we can't use an ephemeral port). Retries alone seeminglydid not fix the test flakes. A new failure mode appeared on the retries: timingout connecting to the database.When a port discovery error occurrs, embedded-postgres does not create thedatabase. If the data directory exists on the next attempt, embedded-postgreswill assume the database has already been created. This seems to cause thetimeout error. Wipe all state between retries to ensure attempts execute thesame logic that creates the database.
@zedkippzedkippforce-pushed thezedkipp/testserver-retry-state branch from9e8ff44 to44948bcCompareNovember 20, 2025 23:54
@zedkipp
Copy link
ContributorAuthor

Yeah, that's a really good point. I updated the comments to better document the intent and potential footgun to future folks that may change this code.

@zedkippzedkipp merged commitb4cc982 intomainNov 21, 2025
30 checks passed
@zedkippzedkipp deleted the zedkipp/testserver-retry-state branchNovember 21, 2025 15:55
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsNov 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@cstyancstyancstyan approved these changes

@EmyrkEmyrkAwaiting requested review from Emyrk

@hugodutkahugodutkaAwaiting requested review from hugodutka

Assignees

@zedkippzedkipp

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@zedkipp@Emyrk@cstyan

[8]ページ先頭

©2009-2025 Movatter.jp