-
-
Notifications
You must be signed in to change notification settings - Fork 884
Description
Description
When a file change triggers a build while an existing build is running, a race condition in engine.go
causes the new build to cancel itself, making the running binary outdated.
Root cause
You make a change to trigger build A. In the buildRun()
function, build A will put true
onto buildRunCh
, and then proceed with its build. While it is building, you make a change to trigger build B. In the start()
function, build B sees that there is a value on buildRunCh
, so it puts a value onto buildRunStopCh
:
// already build and run now
select {
case <-e.buildRunCh:
e.buildRunStopCh <- true
default:
}
In then calls go buildRun()
. Since buildRunCh
is now empty, it will be able to place true
onto it. Directly after, it will see that buildRunStopCh
is not-empty, and will effectively cancel itself.
select {
case <-e.buildRunStopCh:
return
default:
}
Reproduction
Place the following in your .air.toml
file to make the build process take a while. Make a change, wait a little bit (less than 10 seconds), and then make another change - the second one will not be reflected in the running code.
cmd = "echo 'Build started at' $(date +%H:%M:%S) && go build -o ./tmp/main . && echo 'Build complete' && sleep 10"