-
Notifications
You must be signed in to change notification settings - Fork 905
GODRIVER-3361 Improve connection error message. #2027
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
base: master
Are you sure you want to change the base?
Conversation
API Change ReportNo changes found! |
2678a3c
to
e6fe071
Compare
e6fe071
to
076f0df
Compare
x/mongo/driver/topology/errors.go
Outdated
} | ||
if e.Wrapped != nil { | ||
return fmt.Sprintf("connection(%s) %s", e.ConnectionID, e.Wrapped.Error()) | ||
if errors.Is(e.Wrapped, io.EOF) { | ||
messages = append(messages, "socket was unexpectedly 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.
messages = append(messages, "socket was unexpectedly closed") | |
messages = append(messages, "connection closed unexpectedly by the other side") |
The ticket suggests "Wrap[ping] io.EOF with an additional error message, like 'connection closed unexpectedly by the other side'". The idea being that we let the user know nothing driver-side is responsible. When the driver closes a connection I would expect something like this: use of closed network connection
. Here is a gist with both examples: https://gist.github.com/prestonvasquez/bbab8370950e9c98fa422b6b1ae1069a
@@ -28,21 +32,28 @@ type ConnectionError struct { | |||
|
|||
// Error implements the error interface. | |||
func (e ConnectionError) Error() string { |
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.
Suggest adding a compile check for ConnectionError
, I just noticed we don't do this:
var _ error = ConnectionError{}
messages = append(messages, "client timed out waiting for server response") | ||
} else if err, ok := e.Wrapped.(net.Error); ok && err.Timeout() { | ||
messages = append(messages, "client timed out waiting for server response") | ||
} |
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.
the transformNetworkError function will wrap the error with context.DeadlineExceeded. Should we include that case here for safety?
} | ||
if e.Wrapped != nil { | ||
return fmt.Sprintf("connection(%s) %s", e.ConnectionID, e.Wrapped.Error()) | ||
if errors.Is(e.Wrapped, io.EOF) { | ||
messages = append(messages, "connection closed unexpectedly by the other side") |
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.
We should create integration tests that verify all three branches work as expected. For the io.EOF
you could do something like this:
addr := bootstrapConnections(t, 1, func(nc net.Conn) {
_ = nc.Close() // Close the connection "server-side" / "other-side"
})
p := newPool(
poolConfig{Address: address.Address(addr.String())},
)
defer p.close(context.Background())
err := p.ready()
require.NoError(t, err)
conn, err := p.checkOut(context.Background())
fmt.Println(err)
_, err = conn.readWireMessage(context.Background())
fmt.Println(err) // expect io.EOF
The timeout branches would just require holding a server response > than the timeout. I know we already do this with TestBackgroundRead
but that is a secondary check of those tests. We should verify this in a test designed specifically to do som.
GODRIVER-3361
Summary
Improve connection error message.
Background & Motivation