From 7c1f74713e273d1e4f1982466eb6fd96e55e8c4d Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Thu, 12 May 2016 17:57:45 +0200 Subject: event: fixed subscribtions to stopped event mux This fixes an issue where the following would lead to a panic due to a channel being closed twice: * Start mux * Stop mux * Sub to mux * Unsub This is fixed by setting the subscriptions status to closed resulting in the Unsubscribe to ignore the request when called. --- event/event.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'event/event.go') diff --git a/event/event.go b/event/event.go index 57dd52baa..fd0bcfbd4 100644 --- a/event/event.go +++ b/event/event.go @@ -66,6 +66,9 @@ func (mux *TypeMux) Subscribe(types ...interface{}) Subscription { mux.mutex.Lock() defer mux.mutex.Unlock() if mux.stopped { + // set the status to closed so that calling Unsubscribe after this + // call will short curuit + sub.closed = true close(sub.postC) } else { if mux.subm == nil { -- cgit