From ca22d0761bd772d38d229d59b3c72a2e7ca9592c Mon Sep 17 00:00:00 2001
From: Boqin Qin <Bobbqqin@gmail.com>
Date: Fri, 17 Apr 2020 20:51:38 +0800
Subject: [PATCH] event: fix inconsistency in Lock and Unlock (#20933)

Co-authored-by: Felix Lange <fjl@twurst.com>
---
 event/event.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/event/event.go b/event/event.go
index 423278731..920681540 100644
--- a/event/event.go
+++ b/event/event.go
@@ -104,6 +104,7 @@ func (mux *TypeMux) Post(ev interface{}) error {
 // Stop blocks until all current deliveries have finished.
 func (mux *TypeMux) Stop() {
 	mux.mutex.Lock()
+	defer mux.mutex.Unlock()
 	for _, subs := range mux.subm {
 		for _, sub := range subs {
 			sub.closewait()
@@ -111,11 +112,11 @@ func (mux *TypeMux) Stop() {
 	}
 	mux.subm = nil
 	mux.stopped = true
-	mux.mutex.Unlock()
 }
 
 func (mux *TypeMux) del(s *TypeMuxSubscription) {
 	mux.mutex.Lock()
+	defer mux.mutex.Unlock()
 	for typ, subs := range mux.subm {
 		if pos := find(subs, s); pos >= 0 {
 			if len(subs) == 1 {
@@ -125,7 +126,6 @@ func (mux *TypeMux) del(s *TypeMuxSubscription) {
 			}
 		}
 	}
-	s.mux.mutex.Unlock()
 }
 
 func find(slice []*TypeMuxSubscription, item *TypeMuxSubscription) int {
-- 
2.18.1