sketch/loop: fix concurrency handling in port monitor shutdown
The graceful shutdown code assumes it can take the pm.mu lock.
Make the Stop code oblige.
This fixes the issue at hand, but the remaining code still gives
me the heebie jeebies--for example, after calling Stop, there could
still be notifications that come in.
Sketch really shouldn't write concurrent code.
This will work well enough, I guess, until it doesn't,
at which point we'll have to carefully fix up the rats nest.
Before:
2m10s: 1157 runs so far, 36 failures (3.11%)
After:
16m45s: 12484 runs so far, 0 failures
Fixes boldsoftware/bold#446 enough for now
diff --git a/loop/port_monitor.go b/loop/port_monitor.go
index 5dbe617..7eaa98f 100644
--- a/loop/port_monitor.go
+++ b/loop/port_monitor.go
@@ -75,14 +75,14 @@
// Stop stops the port monitor.
func (pm *PortMonitor) Stop() {
pm.mu.Lock()
- defer pm.mu.Unlock()
-
if !pm.running {
+ pm.mu.Unlock()
return
}
pm.running = false
pm.cancel()
+ pm.mu.Unlock()
pm.wg.Wait()
pm.poller.Close()
}