From cc45e21e4c1040c7b1bc78f9ae84da3ce043ba8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 17 Apr 2015 18:23:01 +0200 Subject: [PATCH] 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. --- commands/http/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commands/http/client.go b/commands/http/client.go index 10968a55e..a34c89d1a 100644 --- a/commands/http/client.go +++ b/commands/http/client.go @@ -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