Skip to content

Commit 4e97b9a

Browse files
committed
Gracefully handle Temporary errors from Accept()
This should prevent the Cloud SQL proxy from dying once it e.g. hits the max filedescriptor limit.
1 parent bde7871 commit 4e97b9a

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

cmd/cloud_sql_proxy/proxy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func listenInstance(dst chan<- proxy.Conn, cfg instanceConfig) (net.Listener, er
142142
c, err := l.Accept()
143143
if err != nil {
144144
logging.Errorf("Error in accept for %q on %v: %v", cfg, cfg.Address, err)
145+
if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
146+
continue
147+
}
145148
l.Close()
146149
return
147150
}

proxy/fuse/fuse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ func (r *fsRoot) listenerLifecycle(l net.Listener, instance, path string) {
284284
c, err := l.Accept()
285285
if err != nil {
286286
logging.Errorf("error in Accept for %q: %v", instance, err)
287+
if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
288+
continue
289+
}
287290
break
288291
}
289292
r.newConn(instance, c)

proxy/proxy/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ func NewConnSrc(instance string, l net.Listener) <-chan Conn {
271271
c, err := l.Accept()
272272
if err != nil {
273273
logging.Errorf("listener (%#v) had error: %v", l, err)
274+
if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
275+
continue
276+
}
274277
l.Close()
275278
close(ch)
276279
return

0 commit comments

Comments
 (0)