-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,12 +421,9 @@ func (a *csAttempt) newStream() error { | |
cs.callHdr.PreviousAttempts = cs.numRetries | ||
s, err := a.t.NewStream(cs.ctx, cs.callHdr) | ||
if err != nil { | ||
if _, ok := err.(transport.PerformedIOError); ok { | ||
// Return without converting to an RPC error so retry code can | ||
// inspect. | ||
return err | ||
} | ||
return toRPCErr(err) | ||
// Return without converting to an RPC error so retry code can | ||
// inspect. | ||
return err | ||
} | ||
cs.attempt.s = s | ||
cs.attempt.p = &parser{r: s} | ||
|
@@ -525,19 +522,28 @@ 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 { | ||
pioErr, ok := err.(transport.PerformedIOError) | ||
if ok { | ||
// Unwrap error. | ||
err = toRPCErr(pioErr.Err) | ||
} else { | ||
unprocessed = true | ||
// Error from NewClientStream. | ||
nse, ok := err.(*transport.NewStreamError) | ||
if !ok { | ||
// Unexpected, but assume no I/O was performed and the RPC is not | ||
// fatal, so retry indefinitely. | ||
return nil | ||
} | ||
if !ok && !cs.callInfo.failFast { | ||
// 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. | ||
|
||
// Unwrap and convert error. | ||
err = toRPCErr(nse.Err) | ||
|
||
// Never retry DoNotRetry errors, which indicate the RPC should not be | ||
// retried due to max header list size violation, etc. | ||
if nse.DoNotRetry { | ||
return err | ||
} | ||
|
||
// 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. | ||
if !nse.PerformedIO { | ||
return nil | ||
} | ||
} | ||
|
@@ -546,6 +552,7 @@ func (cs *clientStream) shouldRetry(err error) error { | |
return err | ||
} | ||
// Wait for the trailers. | ||
unprocessed := false | ||
if cs.attempt.s != nil { | ||
<-cs.attempt.s.Done() | ||
unprocessed = cs.attempt.s.Unprocessed() | ||
|
@@ -634,7 +641,7 @@ func (cs *clientStream) shouldRetry(err error) error { | |
// Returns nil if a retry was performed and succeeded; error otherwise. | ||
func (cs *clientStream) retryLocked(lastErr error) error { | ||
for { | ||
cs.attempt.finish(lastErr) | ||
cs.attempt.finish(toRPCErr(lastErr)) | ||
if err := cs.shouldRetry(lastErr); err != nil { | ||
cs.commitAttemptLocked() | ||
return err | ||
|
@@ -661,7 +668,13 @@ func (cs *clientStream) withRetry(op func(a *csAttempt) error, onSuccess func()) | |
for { | ||
if cs.committed { | ||
cs.mu.Unlock() | ||
return op(cs.attempt) | ||
err := op(cs.attempt) | ||
if err != nil { | ||
if nse, ok := err.(*transport.NewStreamError); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it can now. I think I moved that unwrapping there after I wrote this. Fixed. |
||
return toRPCErr(nse.Err) | ||
} | ||
} | ||
return err | ||
} | ||
a := cs.attempt | ||
cs.mu.Unlock() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this unexpected? I would think this is the normal race for retry, and the transport is closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unexpected to not get a
*NewStreamError
fromNewClientStream
. I added the defer to make it always return that type.