Possible data race in os.unix.c:5805:unixTempFileDir
A user of the Go transpiled SQLite library is reporting a data race.
This initialization is not protected by a mutex. Meaning unixTempFileDir is not thread safe per se. I was not able to quickly find if calls to unixTempFileDir are synchronized somewhere else, up the call stack.
I'll probably for now attempt a quick fix by a local patch adding a mutex around the lazy initialization, but I'd like to ask if someone more competent can verify if it is - or is not a bug in the SQLite3 code base. If that's the case it would save me from chasing a bug on my side.
Thanks in advance for anyone's kind help.
(2.1) By Larry Brasfield (larrybr) on 2021-11-19 16:33:12 edited from 2.0 in reply to 1 [link] [source]
(Edited to correct hazard preconditions and reflect fix status.)
This is, technically, a race as claimed. The only potential harm would be when:
Multiple threads initially request the temp directory name at (nearly) the same time in the same process;
For different connections;
On a build with 64-bit pointers;
Running on a 32-bit machine.
This is extremely unlikely to ever happen, of course. Nevertheless, a "cure" has been checked into the source (thanks to Dan.)