Skip to content

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

qingyang-hu
Copy link
Collaborator

GODRIVER-3361

Summary

Improve connection error message.

Background & Motivation

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Apr 25, 2025
Copy link
Contributor

API Change Report

No changes found!

@qingyang-hu qingyang-hu force-pushed the godriver3361 branch 4 times, most recently from 2678a3c to e6fe071 Compare April 28, 2025 20:30
@qingyang-hu qingyang-hu marked this pull request as ready for review April 30, 2025 14:49
@qingyang-hu qingyang-hu requested a review from a team as a code owner April 30, 2025 14:49
}
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")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Member

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")
}
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants