Skip to content

Commit

Permalink
fix: ignore go-fuse ctx in Lookup (#2268)
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 17, 2024
1 parent ea161ac commit ae8ec35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions internal/proxy/fuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,27 @@ func TestFUSEReadDir(t *testing.T) {
}
}

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:reg:mysql", 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)
}
}

func TestFUSEErrors(t *testing.T) {
if testing.Short() {
t.Skip("skipping fuse tests in short mode.")
Expand Down
3 changes: 2 additions & 1 deletion internal/proxy/proxy_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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 ae8ec35

Please sign in to comment.