From 1ba95c1087e7a7c65327f45400f0397683da89c1 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sun, 13 Feb 2022 00:09:17 +0700 Subject: [PATCH] atomic close 2 channels (#3498) --- cmd/sentry/sentry/sentry.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/sentry/sentry/sentry.go b/cmd/sentry/sentry/sentry.go index 008554f91..6524ad59d 100644 --- a/cmd/sentry/sentry/sentry.go +++ b/cmd/sentry/sentry/sentry.go @@ -121,6 +121,8 @@ func (pi *PeerInfo) ClearDeadlines(now time.Time, givePermit bool) int { } func (pi *PeerInfo) Remove() { + pi.lock.Lock() + defer pi.lock.Unlock() pi.removeOnce.Do(func() { close(pi.removed) close(pi.tasks) @@ -128,6 +130,8 @@ func (pi *PeerInfo) Remove() { } func (pi *PeerInfo) Async(f func()) { + pi.lock.Lock() + defer pi.lock.Unlock() select { case <-pi.removed: // noop if peer removed case pi.tasks <- f: