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

connector: don't return ErrBadConn when failing to connect #1020

Merged
merged 1 commit into from Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -91,6 +91,7 @@ Zhenye Xie <xiezhenye at gmail.com>

Barracuda Networks, Inc.
Counting Ltd.
DigitalOcean Inc.
Facebook Inc.
GitHub Inc.
Google Inc.
Expand Down
4 changes: 0 additions & 4 deletions connector.go
Expand Up @@ -44,10 +44,6 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
}

if err != nil {
if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
errLog.Print("net.Error from Dial()': ", nerr.Error())
return nil, driver.ErrBadConn
}
return nil, err
}

Expand Down
30 changes: 30 additions & 0 deletions connector_test.go
@@ -0,0 +1,30 @@
package mysql

import (
"context"
"net"
"testing"
"time"
)

func TestConnectorReturnsTimeout(t *testing.T) {
connector := &connector{&Config{
Net: "tcp",
Addr: "1.1.1.1:1234",
Timeout: 10 * time.Millisecond,
}}

_, err := connector.Connect(context.Background())
if err == nil {
t.Fatal("error expected")
}

if nerr, ok := err.(*net.OpError); ok {
expected := "dial tcp 1.1.1.1:1234: i/o timeout"
if nerr.Error() != expected {
t.Fatalf("expected %q, got %q", expected, nerr.Error())
}
} else {
t.Fatalf("expected %T, got %T", nerr, err)
}
}
2 changes: 1 addition & 1 deletion driver_test.go
Expand Up @@ -1874,7 +1874,7 @@ func TestDialNonRetryableNetErr(t *testing.T) {

func TestDialTemporaryNetErr(t *testing.T) {
testErr := netErrorMock{temporary: true}
testDialError(t, testErr, driver.ErrBadConn)
testDialError(t, testErr, testErr)
}

// Tests custom dial functions
Expand Down