mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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.
This commit is contained in:
parent
661fb0a4b5
commit
cc45e21e4c
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user