analyzer/runtime: Mutating shared `storage.QueryBatch` in multiple go-runtines
ptrus opened this issue · comments
In processRound
the batch
variable is shared and mutated from multiple go-routines concurrently (group.Go
is running functions in new go-routines). This is a race condition and leads to undefined behavior.
The possible solutions are to make the storage.QueryBatch{}
thread-safe to use, or (likely the better alternative) fixing the processRound
to not share the batch variable.
Note: didn't check if there are any other such cases, noticed this one by chance.
Good find, thank you! The runtime analyzer is likely the only remaining culprit, besides stats aggregator after your recent changes. I don't think we use goroutines for batch building anywhere else.
Still, I like making storage.QueryBatch{}
thread-safe to use; it's a more future-proof solution, IMO. I remember I was expecting that approach in #228 before I reviewed it :)
OTOH we could (should?) implement both proposed solutions; for tests and debugging, it can be very useful if the queries are assembled into the final DB batch in a deterministic order.