Skip to content

Bug: race conditions in creating workspace_builds  #1366

Closed
@spikecurtis

Description

@spikecurtis

OS Information

  • OS: n/a
  • Browser (if applicable):
  • Architecture:
  • coder --version: Coder v0.5.4-devel+d847d2b

Spotted while reading code

Steps to Reproduce

  1. execute "start" on a workspace from two clients simultaneously

Expected

one succeeds, other fails

Actual

sometimes, both can succeed

Logs

Screenshot

Notes

The issue is that coderd reads the DB to find the previous build, then later updates that build while adding a new build. The build could be updated and no longer be the latest during this time. What is needed is either:

  1. A query that finds and updates the latest build as well as adds the new build in a single transaction. This requires all "is this an allowed transition" logic to be build into the query.
  2. Start and hold open a transaction while doing multiple queries: reading the latest build, checking for errors, and finally writing the new build.

Metadata

Metadata

Assignees

Labels

apiArea: HTTP API

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions