Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/speedle-ads/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func main() {
// Do not close errChan: the second goroutine may still send to it.
case <-intChan:
log.Info("Interrupt signal")
close(intChan)
signal.Stop(intChan)
}

log.Info("Stopping servers...")
Expand Down
2 changes: 1 addition & 1 deletion cmd/speedle-pms/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func main() {
// Do not close errChan: the second goroutine may still send to it.
case <-intChan:
log.Info("Interrupt signal")
close(intChan)
signal.Stop(intChan)
}

log.Info("Stopping servers...")
Expand Down
9 changes: 7 additions & 2 deletions pkg/store/etcd/etcdStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ func (s *Store) Watch() (pms.StorageChangeChannel, error) {
log.Errorf("panic in Watch outer goroutine: %v", r)
}
close(evalChan)
close(s.stop)
// Note: s.stop is closed by StopWatch (guarded by stopOnce), not
// here, so a panic in this goroutine cannot leave a later
// StopWatch sending on an already-closed channel.
close(errChan)
close(stopChan)
s.wg.Done()
Expand Down Expand Up @@ -762,7 +764,10 @@ func watch(evalChan chan pms.StoreChangeEvent, s *Store, errChan chan error, sto
func (s *Store) StopWatch() {
s.stopOnce.Do(func() {
if s.stop != nil {
s.stop <- struct{}{}
// Close (not send) so every inner watch goroutine's
// `case <-s.stop` fires; a single send would only wake one of
// them. stopOnce makes this idempotent and panic-safe.
close(s.stop)
}
})
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/store/file/fileStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ func (s *Store) Watch() (pms.StorageChangeChannel, error) {
}
watcher.Close()
close(storeChangeChan)
close(s.stop)
// Note: s.stop is closed by StopWatch (guarded by stopOnce), not
// here, so a panic in this goroutine cannot leave a later
// StopWatch sending on an already-closed channel.
}()
for {
select {
Expand Down Expand Up @@ -406,7 +408,9 @@ func (s *Store) Watch() (pms.StorageChangeChannel, error) {
func (s *Store) StopWatch() {
s.stopOnce.Do(func() {
if s.stop != nil {
s.stop <- struct{}{}
// Close (not send) so the watch goroutine's `case <-s.stop`
// fires immediately. stopOnce makes this idempotent and safe.
close(s.stop)
}
})
}
Expand Down
Loading