diff --git a/events.go b/events.go index 04c9a9b2e..4c8604a25 100644 --- a/events.go +++ b/events.go @@ -74,13 +74,15 @@ func (evsw *EventSwitch) RemoveListener(listenerID string) { // Get and remove listener evsw.mtx.RLock() listener := evsw.listeners[listenerID] - delete(evsw.listeners, listenerID) evsw.mtx.RUnlock() - if listener == nil { return } + evsw.mtx.Lock() + delete(evsw.listeners, listenerID) + evsw.mtx.Unlock() + // Remove callback for each event. listener.SetRemoved() for _, event := range listener.GetEvents() {