提交 cc45e21e 作者: Tor Arne Vestbø 提交者: Tor Arne Vestbø

Teach http client to abort channel streaming on context cancellation

When the response includes the X-Chunked-Output header, we treat that
as channel output, and fire up a goroutine to decode the chunks. This
routine need to look for context cancellation so that it can exit
cleanly.
上级 661fb0a4
......@@ -181,6 +181,8 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
dec := json.NewDecoder(httpRes.Body)
outputType := reflect.TypeOf(req.Command().Type)
ctx := req.Context().Context
for {
var v interface{}
var err error
......@@ -194,6 +196,14 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
fmt.Println(err.Error())
return
}
select {
case <-ctx.Done():
close(outChan)
return
default:
}
if err == io.EOF {
close(outChan)
return
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论