Fixed build and SIGINT race condition and massive sleep after SIGINT #177
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.
This PR addresses two issues. The bigger issue is a race condition that I was seeing when
send_interrupt
config is true.When Air successful builds and runs the binary the
e.binRunning
is set totrue
. If then the build fails twice beforee.killCmd(...)
completes (takes 30 second due to sleeping after sending SIGINT) the build logics sends two messages (e.binRunning
is stilltrue
) to thebinStopCh
channel, the 2nd message resulting in a block in the middle ofe.withLock
, holding the lock until the channel has room. When the attempt to kill the previous running command finishes sleeping, it cannot get the lock to sete.binRunning
tofalse
resulting in a dead lock.This PR moves the setting of
Engine.binRunning
tofalse
before trying to interrupt/kill the running process, avoiding the the race condition.The 2nd issue is the sleep was being multiplied by
time.Milliseconds
which was resulting in the duration being multiplied by 1M (see the constants at the bottom of the section at https://golang.org/pkg/time/#pkg-constants).I also adjusted some white space and returns in the
runner/util_linux.go
andrunner/util_darwin.go
to match.