Browse Source

etcdserver/etcdhttp: cancel wait on conn close

Blake Mizerany 11 years ago
parent
commit
8c3450e200
1 changed files with 7 additions and 0 deletions
  1. 7 0
      etcdserver2/etcdhttp/http.go

+ 7 - 0
etcdserver2/etcdhttp/http.go

@@ -58,8 +58,15 @@ func encodeResponse(ctx context.Context, w http.ResponseWriter, resp etcdserver.
 	case resp.Watcher != nil:
 		// TODO(bmizerany): support streaming?
 		defer resp.Watcher.Remove()
+		var nch <-chan bool
+		if x, ok := w.(http.CloseNotifier); ok {
+			nch = x.CloseNotify()
+		}
 		select {
 		case ev = <-resp.Watcher.EventChan:
+		case <-nch:
+			// TODO: log something?
+			return nil
 		case <-ctx.Done():
 			return ctx.Err()
 		}