You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Data race of reading row value of timestamp data type #179
I found a data race with reading data from Databricks simultaneously. For example, from different tables or reading catalogs metadata simultaneously.
A code to reproduce data race is
import (
"context"
"database/sql"
"fmt"
"sync"
"testing"
dbsql "github.com/databricks/databricks-sql-go"
)
func TestDatabricksDataRace(t *testing.T) {
var (
wg sync.WaitGroup
ctx = context.Background()
w = make(chan bool)
routineNum = 10
)
wg.Add(routineNum)
for i := 0; i < routineNum; i++ {
go func() {
defer wg.Done()
<-w
if err := listCatalogs(ctx); err != nil {
fmt.Println("ERROR:", err)
}
}()
}
close(w)
wg.Wait()
}
func listCatalogs(ctx context.Context) error {
connector, err := dbsql.NewConnector(
dbsql.WithServerHostname(cfg.Host),
dbsql.WithPort(int(cfg.Port)),
dbsql.WithAccessToken(cfg.AccessToken),
dbsql.WithHTTPPath(cfg.HTTPPath),
)
if err != nil {
return err
}
db := sql.OpenDB(connector)
defer db.Close()
for i := 0; i < 10; i++ {
err := func() error {
r, err := db.QueryContext(ctx, "SHOW CATALOGS;")
if err != nil {
return err
}
defer r.Close()
for r.Next() {
var s string
if err := r.Scan(&s); err != nil {
return err
}
}
return nil
}()
if err != nil {
return err
}
}
return nil
}
A command to run this test with data race detector:
go test -race -run TestDatabricksDataRace .
A root cause of data race is not initialised field loc of arrow.TimestampType. It initialised in the first call of function arrow.TimestampType :: GetZone().
A workaround of data race is:
func init() {
// init `arrow.TimestampType` before use it.
_, _ = arrow.FixedWidthTypes.Timestamp_us.(*arrow.TimestampType).GetToTimeFunc()
}
@nverkhachoyan The reason for reverting was to maintain backward compatibility with some end-user solutions.
The databricks-sql-go library has been updated to use golang.org/x/net v0.17.0, which addresses all known vulnerabilities. All dependencies adhere to the same versioning level (minor, in this case) as per Go module rules.
However, the data race bug in Apache Arrow v12 still persists.
@kravets-levko Any news on this topic? If bumping past v12 isn't in the near future, would you consider adding the snippet above from @7phs to your code so we don't hit this data race in our code? If arrow is a transient dependency it feels a bit odd to have to import it and hook up an init function just to use databricks-sql-go
Fixed on main by #535, which moved the driver to arrow-go v18.8.0. Its TimestampType now locks the cached time zone, so the init() workaround above is no longer needed. I reproduced the race with the old v12 dependency, then ran cold-start and live parallel timestamp reads on main under go test -race on both the Thrift and SEA backends with no race reported. The fix is on main and not in a release yet; v1.x releases still need the workaround.
Activity
7phs commentedon Nov 20, 2023
Related issue of Apache Arrow - apache/arrow#38795
7phs commentedon May 29, 2024
databricks-sql-goupdated and uses Apache Arrow Go v16 with fixed data race.This bug is fixed now.
7phs commentedon Jun 5, 2024
A bug of a data race still exists with reverting the Apache Arrow version to
v12.nverkhachoyan commentedon Nov 17, 2024
Why was the Apache Arrow version reverted back to v12? It uses
golang.org/x/net v0.7.0which has several vulnerabilities.7phs commentedon Nov 18, 2024
@nverkhachoyan The reason for reverting was to maintain backward compatibility with some end-user solutions.
The
databricks-sql-golibrary has been updated to usegolang.org/x/net v0.17.0, which addresses all known vulnerabilities. All dependencies adhere to the same versioning level (minor, in this case) as per Go module rules.However, the data race bug in Apache Arrow v12 still persists.
You can use the following workaround:
Insert this snippet into any appropriate file that uses Apache Arrow.
bombsimon commentedon Oct 8, 2025
Seems like it had breaking changes, see #228
@kravets-levko Any news on this topic? If bumping past v12 isn't in the near future, would you consider adding the snippet above from @7phs to your code so we don't hit this data race in our code? If arrow is a transient dependency it feels a bit odd to have to import it and hook up an
initfunction just to usedatabricks-sql-gofix: data race on Arrow v12 shared timestamp types (prewarm GetToTime…
vuanhphung commentedon Nov 14, 2026
Fixed on main by #535, which moved the driver to arrow-go v18.8.0. Its
TimestampTypenow locks the cached time zone, so theinit()workaround above is no longer needed. I reproduced the race with the old v12 dependency, then ran cold-start and live parallel timestamp reads on main undergo test -raceon both the Thrift and SEA backends with no race reported. The fix is on main and not in a release yet; v1.x releases still need the workaround.