databricks-sdk-go icon indicating copy to clipboard operation
databricks-sdk-go copied to clipboard

[ISSUE] Config not safe for concurrent use

Open elgohr opened this issue 3 weeks ago • 0 comments
trafficstars

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.

elgohr avatar Oct 22 '25 13:10 elgohr