From eb4435bf74018107915d03d250a78f0fe7541ef3 Mon Sep 17 00:00:00 2001 From: Eno Compton Date: Thu, 25 Apr 2024 17:01:28 -0600 Subject: [PATCH] fix: ensure graceful shutdown on fuse error (#638) If the FUSE mount has not succeeded due to misconfiguration, the Proxy should still shutdown without panicing. Related to https://github.com/GoogleCloudPlatform/cloud-sql-proxy/issues/2013 --- internal/proxy/proxy_other.go | 3 +++ internal/proxy/proxy_other_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/internal/proxy/proxy_other.go b/internal/proxy/proxy_other.go index 7da711d0..96a29904 100644 --- a/internal/proxy/proxy_other.go +++ b/internal/proxy/proxy_other.go @@ -181,6 +181,9 @@ func (c *Client) fuseMounts() []*socketMount { func (c *Client) unmountFUSE() error { c.fuseServerMu.Lock() defer c.fuseServerMu.Unlock() + if c.fuseServer == nil { + return nil + } return c.fuseServer.Unmount() } diff --git a/internal/proxy/proxy_other_test.go b/internal/proxy/proxy_other_test.go index 75e33e2b..6cf701b1 100644 --- a/internal/proxy/proxy_other_test.go +++ b/internal/proxy/proxy_other_test.go @@ -18,8 +18,11 @@ package proxy_test import ( + "context" "os" "testing" + + "github.com/GoogleCloudPlatform/alloydb-auth-proxy/internal/proxy" ) func verifySocketPermissions(t *testing.T, addr string) { @@ -31,3 +34,19 @@ func verifySocketPermissions(t *testing.T, addr string) { t.Fatalf("file mode: want = %v, got = %v", 0777|os.ModeSocket, fm) } } + +func TestFuseClosesGracefully(t *testing.T) { + c, err := proxy.NewClient( + context.Background(), nil, testLogger, + &proxy.Config{ + FUSEDir: t.TempDir(), + FUSETempDir: t.TempDir(), + Token: "mytoken", + }) + if err != nil { + t.Fatal(err) + } + if err := c.Close(); err != nil { + t.Fatal(err) + } +}