From ebedf0bbbf6245cf5b1ff3c8a1297a08e133caf8 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Mon, 16 Feb 2026 12:58:50 +0100 Subject: [PATCH] Lock main client from inside the session client when session requests are made (#71) * Lock outer client from the main client from the session client when used * Add race to test --- .github/workflows/go.yaml | 2 +- client.go | 3 ++- session_client.go | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index d8e3a2b..15d2d12 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -65,4 +65,4 @@ jobs: go-version-file: "go.mod" cache: true - name: Run tests - run: go test ./... + run: go test ./... -race diff --git a/client.go b/client.go index 5889d99..a88e12b 100644 --- a/client.go +++ b/client.go @@ -546,7 +546,6 @@ func parseRunnerScaleSetMessageResponse(respBody io.Reader) (*RunnerScaleSetMess // It exposes client options that could be overwritten, providing ability to specify different retry policies or TLS settings, proxy, etc. func (c *Client) MessageSessionClient(ctx context.Context, runnerScaleSetID int, owner string, options ...HTTPOption) (*MessageSessionClient, error) { c.mu.Lock() - defer c.mu.Unlock() // Copy original options httpClientOption := c.httpClientOption @@ -567,6 +566,8 @@ func (c *Client) MessageSessionClient(ctx context.Context, runnerScaleSetID int, scaleSetID: runnerScaleSetID, session: nil, } + // Unlock the client to allow createMessageSession to call public methods that require locking + c.mu.Unlock() if err := client.createMessageSession(ctx); err != nil { return nil, fmt.Errorf("failed to create message session: %w", err) diff --git a/session_client.go b/session_client.go index 80c20d9..c80556a 100644 --- a/session_client.go +++ b/session_client.go @@ -235,6 +235,9 @@ func (c *MessageSessionClient) Session() RunnerScaleSetSession { } func (c *MessageSessionClient) doSessionRequest(ctx context.Context, method, path string, requestData io.Reader, expectedResponseStatusCode int, responseUnmarshalTarget any) error { + c.innerClient.mu.Lock() + defer c.innerClient.mu.Unlock() + req, err := c.innerClient.newActionsServiceRequest(ctx, method, path, requestData) if err != nil { return fmt.Errorf("failed to create new actions service request: %w", err)