Skip to content

Commit 45271d0

Browse files
committed
Merge pull request #194 from goodinc/master
Enable TCP Keepalives on TCP connections to MySQL
2 parents 9724877 + e762c9b commit 45271d0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Individual Persons
1313

14+
Aaron Hopkins <go-sql-driver at die.net>
1415
Arne Hormann <arnehormann at gmail.com>
1516
Carlos Nieto <jose.carlos at menteslibres.net>
1617
DisposaBoy <disposaboy at dby.me>

driver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ func (d *MySQLDriver) Open(dsn string) (driver.Conn, error) {
5656
if err != nil {
5757
return nil, err
5858
}
59+
60+
// Enable TCP Keepalives on TCP connections
61+
if tc, ok := mc.netConn.(*net.TCPConn); ok {
62+
if err := tc.SetKeepAlive(true); err != nil {
63+
mc.Close()
64+
return nil, err
65+
}
66+
}
67+
5968
mc.buf = newBuffer(mc.netConn)
6069

6170
// Reading Handshake Initialization Packet

0 commit comments

Comments
 (0)