Browse Source

fix close connection when client leaves

Xiang Li 12 years ago
parent
commit
63456b5c4b
1 changed files with 10 additions and 2 deletions
  1. 10 2
      server/v2/get_handler.go

+ 10 - 2
server/v2/get_handler.go

@@ -46,11 +46,19 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
 		}
 		}
 
 
 		// Start the watcher on the store.
 		// Start the watcher on the store.
-		c, err := s.Store().Watch(key, recursive, sinceIndex, s.CommitIndex(), s.Term())
+		eventChan, err := s.Store().Watch(key, recursive, sinceIndex, s.CommitIndex(), s.Term())
 		if err != nil {
 		if err != nil {
 			return etcdErr.NewError(500, key, store.UndefIndex, store.UndefTerm)
 			return etcdErr.NewError(500, key, store.UndefIndex, store.UndefTerm)
 		}
 		}
-		event = <-c
+
+		cn, _ := w.(http.CloseNotifier)
+		closeChan := cn.CloseNotify()
+
+		select {
+		case <-closeChan:
+			return nil
+		case event = <-eventChan:
+		}
 
 
 	} else { //get
 	} else { //get
 		// Retrieve the key from the store.
 		// Retrieve the key from the store.