- Notifications
You must be signed in to change notification settings - Fork948
Commitf751f81
authored
fix(coderd): fix flake in
Fixescoder/internal#521This happened due to a race condition present in how`AwaitWorkspaceBuildJobCompleted` works.`AwaitWorkspaceBuildJobCompleted` works by waiting until`/api/v2/workspacesbuilds/{workspacebuild}/` returns a workspace buildwith `.Job.CompletedAt != nil`. The issue here is that _sometimes_ thereturned `codersdk.WorkspaceBuild` can contain a build from _before_ aprovisioner job completed, but contain the provisioner job from _after_it completed.Let me demonstrate:Here we query the database for `database.WorkspaceBuild`.https://github.com/coder/coder/blob/a3f64f74f794c733126ad21cd1feb0801caf67c4/coderd/coderd.go#L1409-L1415Inside of the `workspaceBuild` route handler, we call`workspaceBuildsData`https://github.com/coder/coder/blob/a3f64f74f794c733126ad21cd1feb0801caf67c4/coderd/workspacebuilds.go#L54This then calls `GetProvisionerJobsByIDsWithQueuePosition`https://github.com/coder/coder/blob/a3f64f74f794c733126ad21cd1feb0801caf67c4/coderd/workspacebuilds.go#L852-L856As these two calls happen _outside of a transaction_, the state of theworld can change underneath. This can result in an in-progress workspacebuild having a completed provisioner job attached to it.TestAPI/ModifyAutostopWithRunningWorkspace
(#18932)1 parent0d3b770 commitf751f81
1 file changed
+8
-3
lines changedLines changed: 8 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2875 | 2875 |
| |
2876 | 2876 |
| |
2877 | 2877 |
| |
2878 |
| - | |
2879 |
| - | |
2880 |
| - | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
2881 | 2881 |
| |
2882 | 2882 |
| |
2883 | 2883 |
| |
2884 | 2884 |
| |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
2885 | 2890 |
| |
2886 | 2891 |
| |
2887 | 2892 |
| |
|
0 commit comments
Comments
(0)