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) + } +}