Skip to content

Commit

Permalink
fix: ensure graceful shutdown on fuse error (#638)
Browse files Browse the repository at this point in the history
If the FUSE mount has not succeeded due to misconfiguration, the Proxy
should still shutdown without panicing.

Related to GoogleCloudPlatform/cloud-sql-proxy#2013
  • Loading branch information
enocom committed Apr 25, 2024
1 parent 2a9175b commit eb4435b
Show file tree
Hide file tree
Showing 2 changed files with 22 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 @@ -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()
}

Expand Down
19 changes: 19 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/alloydb-auth-proxy/internal/proxy"
)

func verifySocketPermissions(t *testing.T, addr string) {
Expand All @@ -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)
}
}

0 comments on commit eb4435b

Please sign in to comment.