etcdserver/etcdhttp: cancel wait on conn close

release-2.0
Blake Mizerany 2014-08-27 16:14:55 -07:00 committed by Yicheng Qin
parent 665af71888
commit 8c3450e200
1 changed files with 7 additions and 0 deletions

View File

@ -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()
}