race condition around randomnessPid
I'm using the excellent library for my sqlite needs, and my test -race is consistently finding a race for randomnessPid variable (I open and close a couple of DBs at startup for each of a go routine worker, so I'll have like 41 go routines opening and reading and closing a total of 82 splits).
================== WARNING: DATA RACE Write at 0x00010266cd38 by goroutine 39: modernc.org/sqlite/lib.unixRandomness() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:22700 +0xed modernc.org/sqlite/lib.Xsqlite3OsRandomness() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:12079 +0x141 modernc.org/sqlite/lib.Xsqlite3_randomness() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:15196 +0x264 modernc.org/sqlite/lib.writeJournalHdr() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:26774 +0xa2c modernc.org/sqlite/lib.pager_open_journal() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:29500 +0x6c6 modernc.org/sqlite/lib.pager_write() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:29610 +0xd8 modernc.org/sqlite/lib.Xsqlite3PagerWrite() /Users/chlane/go/pkg/mod/modernc.org/sqlit modernc.org/sqlite/lib.newDatabase() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:35864 +0x16f modernc.org/sqlite/lib.Xsqlite3BtreeBeginTrans() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:36047 +0x1007 modernc.org/sqlite/lib.Xsqlite3BtreeSetVersion() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:42729 +0x2aa modernc.org/sqlite/lib.Xsqlite3VdbeExec() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:56515 +0x322e modernc.org/sqlite/lib.sqlite3Step() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:48844 +0x1ae modernc.org/sqlite/lib.Xsqlite3_step() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:48918 +0x1c4 github.com/glebarez/go-sqlite.(*conn).step() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite.go:972 +0x51 github.com/glebarez/go-sqlite.( github.com/glebarez/go-sqlite.(*stmt).exec() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite.go:549 +0x25e github.com/glebarez/go-sqlite.(*conn).exec() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite.go:1443 +0x16a github.com/glebarez/go-sqlite.(*conn).ExecContext() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite_go18.go:33 +0xa4 database/sql.ctxDriverExec() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/ctxutil.go:31 +0x10a database/sql.(*DB).execDC.func2() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1679 +0x271 database/sql.withLock() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:3439 +0xa2 database/sql.(*DB).execDC() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1674 +0x2c8 database/sql.(*DB).exec() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1659 +0x149 database/sql.(*DB).ExecContext() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1633 +0xfc database/sql.(*DB).Exec() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1651 +0x404 github.paypal.com/chlane/rl_count_serv/cmd/rl_count_serv.(*persistState).createDB() /Users/chlane/go/src/github.paypal.com/chlane/rl_count_serv/cmd/rl_count_serv/persist_sql.go:55 +0x218
... snipping ...
Previous read at 0x00010266cd38 by goroutine 42: modernc.org/sqlite/lib.unixOpen() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:22236 +0x128 modernc.org/sqlite/lib.Xsqlite3OsOpen() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:12017 +0x17dd modernc.org/sqlite/lib.Xsqlite3PagerOpen() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:28817 +0x15bb modernc.org/sqlite/lib.Xsqlite3BtreeOpen() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:35124 +0x606 modernc.org/sqlite/lib.openDatabase() /Users/chlane/go/pkg/mod/modernc.org/sqlite@v1.19.2/lib/sqlite_darwin_amd64.go:120832 +0x1769 modernc.org/sqlite/lib.Xsqlite3_open_v2() /Users/chlane/go/pkg/mod/m github.com/glebarez/go-sqlite.(*conn).openV2() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite.go:1309 +0x129 github.com/glebarez/go-sqlite.newConn() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite.go:807 +0x1c8 github.com/glebarez/go-sqlite.(*Driver).Open() /Users/chlane/go/pkg/mod/github.com/glebarez/go-sqlite@v1.19.2/sqlite.go:1523 +0x64 database/sql.dsnConnector.Connect() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:759 +0x6e database/sql.(*dsnConnector).Connect() :1 +0x29 database/sql.(*DB).conn() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1393 +0xb11 database/sql.(*DB).exec() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1655 +0x99 database/sql.(*DB).ExecContext() /Users/chlane/homebrew/Cellar/go/1.19.3/libexec/src/database/sql/sql.go:1633 +0xfc database/sql.(*DB).Exec() /Users/chlane/homebrew/ github.paypal.com/chlane/rl_count_serv/cmd/rl_count_serv.(*persistState).createDB() /Users/chlane/go/src/github.paypal.com/chlane/rl_count_serv/cmd/rl_count_serv/persist_sql.go:55 +0x218
I'm pretty sure these are different file names, and I've never had any production issues related to this, so I'm guessing from the names it's kind of expected.
Line 22700 is the assignment at the end here:
func unixRandomness(tls *libc.TLS, NotUsed uintptr, nBuf int32, zBuf uintptr) int32 {
bp := tls.Alloc(8)
defer tls.Free(8)
_ = NotUsed
libc.X__builtin___memset_chk(tls, zBuf, 0, uint64(nBuf), libc.X__builtin_object_size(tls, zBuf, 0))
randomnessPid = libc.Xgetpid(tls)
And line 22236 is in func unixOpen :
if !(randomnessPid != libc.Xgetpid(tls)) {
goto __1
}
randomnessPid = libc.Xgetpid(tls)