From ae8ec359b43056fe815ac7c649388232bc1b4171 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Wed, 17 Jul 2024 16:18:38 -0400 Subject: [PATCH] fix: ignore go-fuse ctx in Lookup (#2268) Ignore context passed into Lookup as it can be cancelled by interrupts in go-fuse. Instead create a new context when Lookup is invoked. --- internal/proxy/fuse_test.go | 21 +++++++++++++++++++++ internal/proxy/proxy_other.go | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/proxy/fuse_test.go b/internal/proxy/fuse_test.go index 269ea290c..bb205fe1b 100644 --- a/internal/proxy/fuse_test.go +++ b/internal/proxy/fuse_test.go @@ -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.") diff --git a/internal/proxy/proxy_other.go b/internal/proxy/proxy_other.go index 47aa3bdc9..f6199167b 100644 --- a/internal/proxy/proxy_other.go +++ b/internal/proxy/proxy_other.go @@ -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 }