Skip to content

Commit

Permalink
fix: ignore go-fuse ctx in Lookup (#675)
Browse files Browse the repository at this point in the history
Ignore context passed into Lookup as it can be cancelled by
interrupts in go-fuse. Instead create a new context when Lookup
is invoked.
  • Loading branch information
jackwotherspoon authored Jul 18, 2024
1 parent d81b90d commit 57d3e80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions internal/proxy/fuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/GoogleCloudPlatform/alloydb-auth-proxy/alloydb"
"github.com/GoogleCloudPlatform/alloydb-auth-proxy/internal/proxy"
"github.com/hanwen/go-fuse/v2/fs"
)

func randTmpDir(t interface {
Expand Down Expand Up @@ -296,3 +297,24 @@ func TestFUSEWithBadDir(t *testing.T) {
t.Fatal("proxy client should fail with bad dir")
}
}

func TestLookupIgnoresContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping fuse tests in short mode.")
}
// create context and cancel it immediately
ctx, cancel := context.WithCancel(context.Background())
cancel()
d := &fakeDialer{}
c, _ := newTestClient(t, d, randTmpDir(t), randTmpDir(t))

// invoke Lookup with cancelled context, should ignore context and succeed
_, err := c.Lookup(ctx, "proj.region.cluster.instance", nil)
if err != fs.OK {
t.Fatalf("proxy.Client.Lookup(): %v", err)
}
// Close the client to close all open sockets.
if err := c.Close(); err != nil {
t.Fatalf("c.Close(): %v", err)
}
}
3 changes: 2 additions & 1 deletion internal/proxy/proxy_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func (c *Client) Readdir(_ context.Context) (fs.DirStream, syscall.Errno) {
// socket is connected to the requested Cloud SQL instance. Lookup returns a
// symlink (instead of the socket itself) so that multiple callers all use the
// same Unix socket.
func (c *Client) Lookup(ctx context.Context, instance string, _ *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
func (c *Client) Lookup(_ context.Context, instance string, _ *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
ctx := context.Background()
if instance == "README" {
return c.NewInode(ctx, &readme{}, fs.StableAttr{}), fs.OK
}
Expand Down

0 comments on commit 57d3e80

Please sign in to comment.