Commit 404589fe authored by Tor Arne Vestbø's avatar Tor Arne Vestbø Committed by 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.
parent f46443c2
......@@ -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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment