Browse Source

fix(mod/lock): Use dedicated channel to shutdown goroutine properly

If closeChan is available and stopWatchChan was closed by defer
select selects a single channel randomly. This causes a panic sending to closed
channel.
TANABE Ken-ichi 12 years ago
parent
commit
4c2942f9f9
1 changed files with 4 additions and 1 deletions
  1. 4 1
      mod/lock/v2/acquire_handler.go

+ 4 - 1
mod/lock/v2/acquire_handler.go

@@ -146,14 +146,17 @@ func (h *handler) ttlKeepAlive(k string, value string, ttl int, stopChan chan bo
 func (h *handler) watch(keypath string, index int, closeChan <- chan bool) error {
 	// Wrap close chan so we can pass it to Client.Watch().
 	stopWatchChan := make(chan bool)
+	stopWrapChan := make(chan bool)
 	go func() {
 		select {
 		case <- closeChan:
 			stopWatchChan <- true
+		case <- stopWrapChan:
+			stopWatchChan <- true
 		case <- stopWatchChan:
 		}
 	}()
-	defer close(stopWatchChan)
+	defer close(stopWrapChan)
 
 	for {
 		// Read all nodes for the lock.