Backend: Race condition when enqueuing builds to run
Summary
In Ci::PlayBuildService#play
, we run two commands: build.enqueue
, followed by build.update(current_user: ..., job_variables_attributes: ...)
I think it's theoretically possible for us to enqueue a build, which is then picked up and run without the correct user or job variables set.
Steps to reproduce
-
Create a config with a manual job with variables:
-
In order to reproduce this, place a
sleep(500)
betweenbuild.enqueue
andbuild.update
variables:
DEPLOY_TO_TEST:
value: "this is variable deploy to test"
deploy_job:
when: manual
script: echo "$DEPLOY_TO_STAGE" # for ease of testing
- Run a pipeline
- Click on the manual job
deploy_job
- Change the value of
DEPLOY_TO_STAGE
and click onTrigger this manual action
The variable value for DEPLOY_TO_STAGE
will remain unchanged.
What is the current bug behavior?
Job runs without correct variables set
Affected jobs are when jobs are run manually.
What is the expected correct behavior?
Job should not be enqueued until the system is ready to service it fully. To test it, run the steps above and the variable outputted by the ECHO
statement should change.
Possible fixes
/cc @matteeyah
Edited by Mark Nuzzo