There is a potential race condition when a notifier is run in a new thread and then immediately stopped in the original thread. If Notifier#stop sets @stop = true before Notifier#run sets @stop = false, then Notifier#run will loop until Notifier#stop is called again. Furthermore, if Notifier#run acquires the @running mutex before Notifier#stop does (but after Notifier#stop sets @stop = true), then Notifier#stop will get stuck waiting for the mutex while Notifier#run infinitely loops.
This commit modifies Notifier#run to assume @stop == false when it begins, and to reset @stop = false only after its loop terminates, thus eliminating the race.
Coverage decreased (-0.009%) to 80.374% when pulling 83abe4d5ecab7831bf3cc962e435aaa317819f93 on jonathanhefner:notifier-run-stop-race-condition into 3cee3331033a9d2cb642076de8aefac3bf0f4e3b on guard:master.
There is a potential race condition when a notifier is run in a new thread and then immediately stopped in the original thread. If
Notifier#stop
sets@stop = true
beforeNotifier#run
sets@stop = false
, thenNotifier#run
will loop untilNotifier#stop
is called again. Furthermore, ifNotifier#run
acquires the@running
mutex beforeNotifier#stop
does (but afterNotifier#stop
sets@stop = true
), thenNotifier#stop
will get stuck waiting for the mutex whileNotifier#run
infinitely loops.This commit modifies
Notifier#run
to assume@stop == false
when it begins, and to reset@stop = false
only after its loop terminates, thus eliminating the race.