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

client: ensure cancel is always called when func exits

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