Skip to content

Commit

Permalink
fix: ensure proxy shutsdown cleanly on fuse error (#2205)
Browse files Browse the repository at this point in the history
If the fuse server fails to mount, the call to Close should not panic.
This commit ensures that no panic's happen if fuse isn't properly
configured.

Fixes #2013
  • Loading branch information
enocom authored Apr 26, 2024
1 parent 3f9e2de commit 54e65d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/proxy/proxy_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,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()
}

Expand Down
20 changes: 20 additions & 0 deletions internal/proxy/proxy_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
package proxy_test

import (
"context"
"os"
"testing"

"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/proxy"
)

var (
Expand All @@ -40,3 +43,20 @@ 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)
}

}

0 comments on commit 54e65d1

Please sign in to comment.