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
This commit is contained in:
@@ -65,4 +65,4 @@ jobs:
|
||||
go-version-file: "go.mod"
|
||||
cache: true
|
||||
- name: Run tests
|
||||
run: go test ./...
|
||||
run: go test ./... -race
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user