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(coderd): fix flake inTestAPI/ModifyAutostopWithRunningWorkspace#18932

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
DanielleMaywood merged 1 commit intomainfromdanielle/fix-workspace-update-ttl
Jul 21, 2025

Conversation

DanielleMaywood
Copy link
Contributor

@DanielleMaywoodDanielleMaywood commentedJul 21, 2025
edited
Loading

Fixescoder/internal#521

This happened due to a race condition present in howAwaitWorkspaceBuildJobCompleted works.

AwaitWorkspaceBuildJobCompleted works by waiting until/api/v2/workspacesbuilds/{workspacebuild}/ returns a workspace build with.Job.CompletedAt != nil. The issue here is thatsometimes the returnedcodersdk.WorkspaceBuild can contain a build frombefore a provisioner job completed, but contain the provisioner job fromafter it completed.

Let me demonstrate:

Here we query the database fordatabase.WorkspaceBuild.

coder/coderd/coderd.go

Lines 1409 to 1415 ina3f64f7

r.Route("/workspacebuilds/{workspacebuild}",func(r chi.Router) {
r.Use(
apiKeyMiddleware,
httpmw.ExtractWorkspaceBuildParam(options.Database),
httpmw.ExtractWorkspaceParam(options.Database),
)
r.Get("/",api.workspaceBuild)

Inside of theworkspaceBuild route handler, we callworkspaceBuildsData

data,err:=api.workspaceBuildsData(ctx, []database.WorkspaceBuild{workspaceBuild})

This then callsGetProvisionerJobsByIDsWithQueuePosition

jobs,err:=api.Database.GetProvisionerJobsByIDsWithQueuePosition(ctx, database.GetProvisionerJobsByIDsWithQueuePositionParams{
IDs:jobIDs,
StaleIntervalMS:provisionerdserver.StaleInterval.Milliseconds(),
})
iferr!=nil&&!errors.Is(err,sql.ErrNoRows) {

As these two calls happenoutside of a transaction, the state of the world can change underneath. This can result in an in-progress workspace build having a completed provisioner job attached to it.

Note: The change in this PR only touches the flakey test. The underlying cause of the flake isn't being fixed. I'm happy to expand the scope of this PR to fix the cause of the flake as that might also fix other flakes.

@DanielleMaywoodDanielleMaywood marked this pull request as ready for reviewJuly 21, 2025 11:18
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a flaky testTestAPI/ModifyAutostopWithRunningWorkspace caused by a race condition inAwaitWorkspaceBuildJobCompleted. The issue occurs when the API returns stale workspace build data due to non-transactional database queries between workspace builds and provisioner jobs.

  • Adds a re-fetch of the workspace build before accessing its deadline to ensure fresh data
  • Restructures the test flow to validate the deadline state before making TTL updates
Comments suppressed due to low confidence (1)

coderd/workspaces_test.go:2880

  • The variable name 'build' is being reused and shadows the original build variable from the outer scope. Consider using a more descriptive name like 'freshBuild' or 'updatedBuild' to avoid confusion.
build, err := client.WorkspaceBuild(ctx, build.ID)

@DanielleMaywoodDanielleMaywood merged commitf751f81 intomainJul 21, 2025
40 checks passed
@DanielleMaywoodDanielleMaywood deleted the danielle/fix-workspace-update-ttl branchJuly 21, 2025 12:04
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

Copilot code reviewCopilotCopilot left review comments

@johnstcnjohnstcnjohnstcn approved these changes

@mtojekmtojekAwaiting requested review from mtojek

Assignees

@DanielleMaywoodDanielleMaywood

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

flake:TestWorkspaceUpdateTTL
2 participants
@DanielleMaywood@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp