Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: fix detection of whether IO was performed in NewStream #4611

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,17 @@ func (p PerformedIOError) Error() string {
// NewStream creates a stream and registers it into the transport as "active"
// streams.
func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Stream, err error) {
defer func() {
if err != nil && (len(t.perRPCCreds) > 0 || callHdr.Creds != nil) {
// We may have performed I/O in the per-RPC creds callback, so do not
// allow transparent retry.
err = PerformedIOError{err}
}
}()
ctx = peer.NewContext(ctx, t.getPeer())
headerFields, err := t.createHeaderFields(ctx, callHdr)
if err != nil {
// We may have performed I/O in the per-RPC creds callback, so do not
// allow transparent retry.
return nil, PerformedIOError{err}
return nil, err
}
s := t.newStream(ctx, callHdr)
cleanup := func(err error) {
Expand Down
24 changes: 15 additions & 9 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,27 +525,33 @@ func (cs *clientStream) commitAttempt() {
// shouldRetry returns nil if the RPC should be retried; otherwise it returns
// the error that should be returned by the operation.
func (cs *clientStream) shouldRetry(err error) error {
unprocessed := false
if cs.attempt.s == nil {
// Error from NewClientStream.
pioErr, ok := err.(transport.PerformedIOError)
if ok {
// Unwrap error.
err = toRPCErr(pioErr.Err)
} else {
unprocessed = true
}
if !ok && !cs.callInfo.failFast {
if !ok {
// In the event of a non-IO operation error from NewStream, we
// never attempted to write anything to the wire, so we can retry
// indefinitely for non-fail-fast RPCs.
// indefinitely. Except for INTERNAL errors, which indicate the
// RPC should not be retried due to max header list size violation.
if status.Convert(err).Code() == codes.Internal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly concerned about this check for codes.Internal. Would there be an Internal error that's retriable? Should we make another export type to wrap this? DoNotRetryThisItWillFailAgainError

Copy link
Member Author

@dfawley dfawley Jul 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The flow around error handling is pretty complex because of the need to wrap & unwrap errors. I thought about implementing Unwrap() error or implementing GRPCStatus() on NewStreamError but I think this is okay. LMK what you think.

return err
}
return nil
}
// Unwrap error.
err = toRPCErr(pioErr.Err)
// INTERNAL errors from NewStream indicate the RPC should not be
// retried.
if status.Convert(err).Code() == codes.Internal {
return err
}
}
if cs.finished || cs.committed {
// RPC is finished or committed; cannot retry.
return err
}
// Wait for the trailers.
unprocessed := false
if cs.attempt.s != nil {
<-cs.attempt.s.Done()
unprocessed = cs.attempt.s.Unprocessed()
Expand Down