Skip to content

Commit 2ec72f4

Browse files
sigxcpu76hfwang
authored andcommitted
add TCP keep-alive to client side (GoogleCloudPlatform#161)
Fixes GoogleCloudPlatform#147 where it takes awhile for the cloud sql proxy to notice that a client has disappeared, resulting in "wasted" database connections. Since customers can't control the max connection limit, this was causing some pain.
1 parent ec8f5ac commit 2ec72f4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cmd/cloud_sql_proxy/proxy.go

+7
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func listenInstance(dst chan<- proxy.Conn, cfg instanceConfig) (net.Listener, er
155155
return
156156
}
157157
logging.Verbosef("New connection for %q", cfg.Instance)
158+
159+
switch clientConn := c.(type) {
160+
case *net.TCPConn:
161+
clientConn.SetKeepAlive(true)
162+
clientConn.SetKeepAlivePeriod(1 * time.Minute)
163+
164+
}
158165
dst <- proxy.Conn{cfg.Instance, c}
159166
}
160167
}()

0 commit comments

Comments
 (0)