Skip to content

Commit

Permalink
fix: Use lock and queue.CloseAndDiscard for watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Oct 21, 2022
1 parent 82064e3 commit 0b277a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,15 @@ func (s *Server) Close(ctx context.Context) error {
s.serveErrCh.Close()

// Close any watchers.
s.watchersLock.Lock()
defer s.watchersLock.Unlock()

for _, watcher := range s.watchers {
watcher.Close()
}

s.watchers = nil

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ func (w *Watcher[T]) Send(event T) bool {
}

func (w *Watcher[T]) Close() {
w.eventCh.Close()
w.eventCh.CloseAndDiscardQueued()
}

0 comments on commit 0b277a6

Please sign in to comment.