diff --git a/ethmonitor/ethmonitor.go b/ethmonitor/ethmonitor.go index a081427b..49ec00df 100644 --- a/ethmonitor/ethmonitor.go +++ b/ethmonitor/ethmonitor.go @@ -986,8 +986,11 @@ func (m *Monitor) NumSubscribers() int { func (m *Monitor) UnsubscribeAll(err error) { m.mu.Lock() - defer m.mu.Unlock() - for _, sub := range m.subscribers { + var subs []*subscriber + subs = append(subs, m.subscribers...) + m.mu.Unlock() + + for _, sub := range subs { sub.err = err sub.Unsubscribe() }