etcdserver/etcdhttp: cancel wait on conn close

This commit is contained in:
Blake Mizerany 2014-08-27 16:14:55 -07:00 committed by Yicheng Qin
parent 665af71888
commit 8c3450e200

View File

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