Commit 63dad441 authored by Michael Schurter's avatar Michael Schurter
Browse files

client: ensure cancel is always called when func exits

parent 564854dd
Showing with 2 additions and 5 deletions
+2 -5
......@@ -356,10 +356,11 @@ func (s *HTTPServer) fsStreamImpl(resp http.ResponseWriter,
// Create a channel that decodes the results
errCh := make(chan HTTPCodedError)
go func() {
defer cancel()
// Send the request
if err := encoder.Encode(args); err != nil {
errCh <- CodedError(500, err.Error())
cancel()
return
}
encoder.Reset(httpPipe)
......@@ -368,7 +369,6 @@ func (s *HTTPServer) fsStreamImpl(resp http.ResponseWriter,
select {
case <-ctx.Done():
errCh <- nil
cancel()
return
default:
}
......@@ -376,7 +376,6 @@ func (s *HTTPServer) fsStreamImpl(resp http.ResponseWriter,
var res cstructs.StreamErrWrapper
if err := decoder.Decode(&res); err != nil {
errCh <- CodedError(500, err.Error())
cancel()
return
}
decoder.Reset(httpPipe)
......@@ -384,14 +383,12 @@ func (s *HTTPServer) fsStreamImpl(resp http.ResponseWriter,
if err := res.Error; err != nil {
if err.Code != nil {
errCh <- CodedError(int(*err.Code), err.Error())
cancel()
return
}
}
if _, err := io.Copy(output, bytes.NewBuffer(res.Payload)); err != nil {
errCh <- CodedError(500, err.Error())
cancel()
return
}
}
......
Supports Markdown
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