Skip to content

fix(cli/ssh): retry on autostart conflict #16058

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 8, 2025
Merged

fix(cli/ssh): retry on autostart conflict #16058

merged 6 commits into from
Jan 8, 2025

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Jan 7, 2025

Fixes #13032

@mafredri mafredri self-assigned this Jan 7, 2025
@mafredri mafredri requested review from johnstcn and mtojek January 7, 2025 16:46
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mafredri
Copy link
Member Author

mafredri commented Jan 7, 2025

It looks like macOS runner is failing due to race as I feared. I can't think of a good way to enforce that this fix is hit without internal testing. Essentially I'd want to either mock the client or the API to block requests to client.CreateWorkspaceBuild or POST to /api/v2/workspaces/%s/builds until all commands are synced in execution.

We could also just remove the count assertion but then we have no way to know that we're actually hitting the edge case.

Got any better ideas @johnstcn @mtojek ?

@mafredri mafredri force-pushed the mafredri/fix-13032 branch from 8e9690a to e5bee0b Compare January 7, 2025 17:24
@johnstcn
Copy link
Member

johnstcn commented Jan 7, 2025

Got any better ideas @johnstcn @mtojek ?

github.com/coder/quartz? 😅

That, or dbmock could let you do something like

dbmock.EXPECT().InsertWorkspaceBuild(gomock.Any(), gomock.Any().Do(func() {
<-waitForCommand
}).AndReturn(...)

@mafredri
Copy link
Member Author

mafredri commented Jan 7, 2025

Got any better ideas @johnstcn @mtojek ?

github.com/coder/quartz? 😅

That, or dbmock could let you do something like

dbmock.EXPECT().InsertWorkspaceBuild(gomock.Any(), gomock.Any().Do(func() {
<-waitForCommand
}).AndReturn(...)

Thanks for the suggestions. Quartz is a bit too distant / side-effecty to properly do this I think 😅. I'll look into dbmock but that only works if it actually passes the invocation to a real DB. Don't want to mock all DB calls required to do this E2E so might be easiest via some kind of middleware used in tests where you can intercept any request before passing it on to the next handler.

@johnstcn
Copy link
Member

johnstcn commented Jan 7, 2025

might be easiest via some kind of middleware used in tests where you can intercept any
request before passing it on to the next handler.

That's actually pretty nice! It seems like it should be simple enough to allow wrapping coderAPI.RootHandler with a middleware in coderdtest.NewWithAPI.

@mafredri mafredri force-pushed the mafredri/fix-13032 branch from ced390c to 042bd42 Compare January 8, 2025 11:44
// Intercept builds to synchronize execution of the SSH command.
// The purpose here is to make sure all commands try to trigger
// a start build of the workspace.
isFirstBuild := true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe make this an atomic.Bool or a sync.Once?

@mafredri mafredri merged commit ba6e84d into main Jan 8, 2025
30 checks passed
@mafredri mafredri deleted the mafredri/fix-13032 branch January 8, 2025 13:15
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI should gracefully handle "409: A workspace build is already active" error on autostart
3 participants