From a3473761a3fea4daa7abf6a4e4acb7fd004db9a8 Mon Sep 17 00:00:00 2001 From: jackwotherspoon Date: Thu, 18 Jul 2024 14:29:57 +0000 Subject: [PATCH 1/2] fix: ignore context in Lookup --- internal/proxy/fuse_test.go | 22 ++++++++++++++++++++++ internal/proxy/proxy_other.go | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/proxy/fuse_test.go b/internal/proxy/fuse_test.go index 2a0b5574..1aff5bbd 100644 --- a/internal/proxy/fuse_test.go +++ b/internal/proxy/fuse_test.go @@ -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 { @@ -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: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) + } +} diff --git a/internal/proxy/proxy_other.go b/internal/proxy/proxy_other.go index 96a29904..1851efcc 100644 --- a/internal/proxy/proxy_other.go +++ b/internal/proxy/proxy_other.go @@ -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 } From ccb15ee0a94ca33cab9ba23ea64bc2269700f0a1 Mon Sep 17 00:00:00 2001 From: jackwotherspoon Date: Thu, 18 Jul 2024 14:37:35 +0000 Subject: [PATCH 2/2] chore: use instance URI format --- internal/proxy/fuse_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/proxy/fuse_test.go b/internal/proxy/fuse_test.go index 1aff5bbd..0842dd85 100644 --- a/internal/proxy/fuse_test.go +++ b/internal/proxy/fuse_test.go @@ -309,7 +309,7 @@ func TestLookupIgnoresContext(t *testing.T) { 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) + _, err := c.Lookup(ctx, "proj.region.cluster.instance", nil) if err != fs.OK { t.Fatalf("proxy.Client.Lookup(): %v", err) }