From 1a37c0a870357a71c0b21d8f8e8fe2d28d0aefa8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 11 Feb 2018 12:51:50 -0800 Subject: [PATCH] avoid publishing if notification system has been shut down (will deadlock) License: MIT Signed-off-by: Steven Allen --- exchange/bitswap/notifications/notifications.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/exchange/bitswap/notifications/notifications.go b/exchange/bitswap/notifications/notifications.go index defea700a..9a6f10b52 100644 --- a/exchange/bitswap/notifications/notifications.go +++ b/exchange/bitswap/notifications/notifications.go @@ -36,6 +36,16 @@ type impl struct { } func (ps *impl) Publish(block blocks.Block) { + ps.wg.Add(1) + defer ps.wg.Done() + + select { + case <-ps.cancel: + // Already shutdown, bail. + return + default: + } + ps.wrapped.Pub(block, block.Cid().KeyString()) }