[WIP] fix: test multiple lifecycle executors flake #19456
Draft
+7
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work in progress!
fixes coder/internal#455
This PR moves incrementing the workspace build number into the insert workspace build query so the operation is atomic.
I'm not exactly sure if this is the right fix yet.
Theory:
You can hit a race condition where the lifecycle executor takes a lock on the workspace, but it's only scoped to prevent multiple lifecycle executors from operating on the workspace at the same time:
ok, err := tx.TryAcquireLock(e.ctx, database.GenLockID(fmt.Sprintf("lifecycle-executor:%s", wsID)))
A manual action (like clicking "start workspace" or perhaps an API call in a concurrent build) can compete with a lifecycle executor.
I need to dig into how concurrent builds work to actually verify what's going on here.
Edit: the fix will probably involve moving the build_number field over to a serial type, it seems I just moved the race condition to the database