Skip to content

Commit

Permalink
Update a couple of more places where we should return a context error…
Browse files Browse the repository at this point in the history
… if there is one (#709)

With an HTTP/2 server implementation that eagerly performs a
server-side cancelation of the stream upon seeing its deadline
elapse, the client could end up returning a "canceled" error code,
due to receiving a "RSTStream" frame, but should ideally return
a "deadline exceeded" error instead. This fixes things so that it
will instead return "deadline exceeded" in this situation.
  • Loading branch information
jhump authored Mar 13, 2024
1 parent befee1d commit c22fe4f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions duplex_http_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (d *duplexHTTPCall) sendUnary(payload messagePayload) (int64, error) {
return payloadLength, nil
}

// Close the request body. Callers *must* call CloseWrite before Read when
// CloseWrite closes the request body. Callers *must* call CloseWrite before Read when
// using HTTP/1.x.
func (d *duplexHTTPCall) CloseWrite() error {
// Even if Write was never called, we need to make an HTTP request. This
Expand Down Expand Up @@ -226,7 +226,11 @@ func (d *duplexHTTPCall) Read(data []byte) (int, error) {
return 0, wrapIfContextError(err)
}
n, err := d.response.Body.Read(data)
return n, wrapIfRSTError(err)
if err != nil && !errors.Is(err, io.EOF) {
err = wrapIfContextDone(d.ctx, err)
err = wrapIfRSTError(err)
}
return n, err
}

func (d *duplexHTTPCall) CloseRead() error {
Expand All @@ -241,7 +245,7 @@ func (d *duplexHTTPCall) CloseRead() error {
errors.Is(err, context.DeadlineExceeded) {
err = closeErr
}
err = wrapIfContextError(err)
err = wrapIfContextDone(d.ctx, err)
return wrapIfRSTError(err)
}

Expand Down

0 comments on commit c22fe4f

Please sign in to comment.