File tree Expand file tree Collapse file tree 1 file changed +4
-22
lines changed Expand file tree Collapse file tree 1 file changed +4
-22
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,11 @@ package mysql
11
11
import (
12
12
"context"
13
13
"database/sql/driver"
14
- "errors"
15
14
"fmt"
16
15
"net"
17
16
"os"
18
17
"strconv"
19
18
"strings"
20
- "syscall"
21
19
)
22
20
23
21
type connector struct {
@@ -100,11 +98,10 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
100
98
}
101
99
102
100
// Enable TCP Keepalives on TCP connections
103
- if err := enableKeepAlive (mc .netConn ); err != nil {
104
- // Don't send COM_QUIT before handshake.
105
- mc .netConn .Close ()
106
- mc .netConn = nil
107
- return nil , err
101
+ if tc , ok := mc .netConn .(* net.TCPConn ); ok {
102
+ if err := tc .SetKeepAlive (true ); err != nil {
103
+ c .cfg .Logger .Print (err )
104
+ }
108
105
}
109
106
110
107
// Call startWatcher for context support (From Go 1.8)
@@ -188,18 +185,3 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
188
185
func (c * connector ) Driver () driver.Driver {
189
186
return & MySQLDriver {}
190
187
}
191
-
192
- func enableKeepAlive (nc net.Conn ) error {
193
- if tc , ok := nc .(* net.TCPConn ); ok {
194
- if err := tc .SetKeepAlive (true ); err != nil {
195
- // The underlying setsockopt syscall may return ENOPROTOOPT if the
196
- // system does not support TCP keep-alive. We can still successfully
197
- // use the driver without keep-alive support, which is why we choose
198
- // to silence it here.
199
- if ! errors .Is (err , syscall .ENOPROTOOPT ) {
200
- return err
201
- }
202
- }
203
- }
204
- return nil
205
- }
You can’t perform that action at this time.
0 commit comments