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.
This commit is contained in:
Matt Jaffee 2018-08-20 09:40:08 -05:00
parent e426c4215e
commit 847132d02a
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -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")