Skip to content

Commit b638f45

Browse files
committed
add flag for ignoring bad connections
1 parent fed23e4 commit b638f45

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ CPU may be throttled and a background refresh cannot run reliably
527527
against all specified instances. If an instance is unreachable, the Proxy exits with a failure
528528
status code.`)
529529

530+
localFlags.BoolVar(&c.conf.IgnoreFailedConnections, "ignore-failed-connections", false,
531+
`If set, the Proxy will not exit on startup when Cloud SQL instances are unreachable.`)
532+
530533
// Global and per instance flags
531534
localFlags.StringVarP(&c.conf.Addr, "address", "a", "127.0.0.1",
532535
"(*) Address to bind Cloud SQL instance listeners.")

internal/proxy/proxy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ type Config struct {
267267
// RunConnectionTest determines whether the Proxy should attempt a connection
268268
// to all specified instances to verify the network path is valid.
269269
RunConnectionTest bool
270+
271+
// IgnoreFailedConnections determines whether the Proxy should ignore failed
272+
// connections to Cloud SQL instances instead of exiting on startup.
273+
IgnoreFailedConnections bool
270274
}
271275

272276
// dialOptions interprets appropriate dial options for a particular instance
@@ -546,6 +550,11 @@ func NewClient(ctx context.Context, d cloudsql.Dialer, l cloudsql.Logger, conf *
546550
for _, inst := range conf.Instances {
547551
m, err := c.newSocketMount(ctx, conf, pc, inst)
548552
if err != nil {
553+
if conf.IgnoreFailedConnections {
554+
l.Errorf("[%v] Unable to mount socket: %v (ignoring due to ignore-failed-connections flag)", inst.Name, err)
555+
continue
556+
}
557+
549558
for _, m := range mnts {
550559
mErr := m.Close()
551560
if mErr != nil {

0 commit comments

Comments
 (0)