Skip to content

[ISSUE] Config not safe for concurrent use #1310

@elgohr

Description

@elgohr

Description
Using config.Config in a concurrent usecase (e.g. multiple clients using the same config or concurrent calls to different methods on the same client) leads to race-conditions.

Reproduction

func TestConcurrency(t *testing.T) {
	cl, err := databricks.NewAccountClient(&databricks.Config{
		Host:          "https://accounts.azuredatabricks.net",
		AccountID:     "SET_ME",
	})
	if err != nil {
		t.Fatal(err)
	}
	g, ctx := errgroup.WithContext(t.Context())
	g.Go(func() error {
		_, err := cl.Workspaces.GetByWorkspaceName(ctx, "test")
		return err
	})
	g.Go(func() error {
		_, err := cl.Workspaces.GetByWorkspaceName(ctx, "test")
		return err
	})
	if err := g.Wait(); err != nil {
		t.Fatal(err)
	}
}

Executed as go test -race ./...

Expected behavior
Enable concurrent use.

Is it a regression?
Don't know

Additional context
Workaround for initialization: Call GetTokenSource after initializing, so that the token gets set.

func TestConcurrency(t *testing.T) {
	cl, err := databricks.NewAccountClient(&databricks.Config{
		Host:          "https://accounts.azuredatabricks.net",
		AccountID:     "SET_ME",
	})
	if err != nil {
		t.Fatal(err)
	}
        _ = cl.Config.GetTokenSource() // <<<<
	g, ctx := errgroup.WithContext(t.Context())
	g.Go(func() error {
		_, err := cl.Workspaces.GetByWorkspaceName(ctx, "test")
		return err
	})
	g.Go(func() error {
		_, err := cl.Workspaces.GetByWorkspaceName(ctx, "test")
		return err
	})
	if err := g.Wait(); err != nil {
		t.Fatal(err)
	}
}

No workaround for token updates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions