From 847132d02aadd37fac280fe9a89597b68d8f18af Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 20 Aug 2018 09:40:08 -0500 Subject: [PATCH] fix race on replicationClosing channel monitorReplication is now not allowed to return until the goroutine it starts cancels the context. Previously, it could return just before the context was canceled which caused a race between its internal goroutine and handlePrimaryStoreEvent which recreates a channel which that internal goroutine was listening on. handlePrimaryStoreEvent already correctly made sure that monitorReplication had returned before recreating the channel, so proper handling of the sub-goroutine of monitorReplication was all that was needed to avoid this race. --- translate.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/translate.go b/translate.go index 32bcc1126..41f3b4852 100644 --- a/translate.go +++ b/translate.go @@ -337,9 +337,7 @@ func (s *TranslateFile) monitorReplication() { } select { - case <-s.closing: - return - case <-s.replicationClosing: + case <-ctx.Done(): return case <-time.After(s.replicationRetryInterval): log.Printf("pilosa: reconnecting to primary replica")