-
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: option to surface connection errors to callers #3430
Conversation
This commit allows blocking clients to receive a more informative error message than "context deadline exceeded", which is especially helpful in tracking down persistent client misconfiguration (such as an invalid TLS certificate, an invalid server that's refusing connections, etc.)
Rather than introducing a sudden interface change, provide an option for consumers to opt in to the new interface.
dialoptions.go
Outdated
// WithReturnLastError returns a DialOption which makes the client connection | ||
// return the last connection error that occurred instead of a context.DeadlineExceeded error. | ||
// Implies WithBlock() | ||
func WithReturnLastError() DialOption { |
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.
Please add an experimental tag for now (see other experimental dial options).
dialoptions.go
Outdated
@@ -298,6 +299,16 @@ func WithBlock() DialOption { | |||
}) | |||
} | |||
|
|||
// WithReturnLastError returns a DialOption which makes the client connection | |||
// return the last connection error that occurred instead of a context.DeadlineExceeded error. |
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.
Please clarify that this returns the connection error string in addition to the context error, not instead of the context error.
dialoptions.go
Outdated
@@ -298,6 +299,16 @@ func WithBlock() DialOption { | |||
}) | |||
} | |||
|
|||
// WithReturnLastError returns a DialOption which makes the client connection |
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.
Regarding the name, WithReturnConnectionError
is preferable to us.
Additionally, clarify documentation around what exactly it does.
Thank you for the PR! |
case err == nil || !cc.dopts.returnLastError: | ||
conn, err = nil, ctx.Err() | ||
default: | ||
conn, err = nil, fmt.Errorf("%v: %v", ctx.Err(), err) |
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.
Wouldn't it be better for the second %v
to be %w
here, so the error is wrapped and thus available for introspection?
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.
This commit allows blocking clients to receive a more informative error
message than "context deadline exceeded", which is especially helpful in
tracking down persistent client misconfiguration (such as an invalid TLS
certificate, an invalid server that's refusing connections, etc.)