bluesky-social/indigo

hepa: race condition with `lastSeq` variable

bnewbold opened this issue · 2 comments

I'm playing fast and loose with a variable (lastSeq) in the hepa main process, which is written every time a new event is processed, and read occasionally by a thread which persists "last seen" to redis.

The data race detector doesn't like this. Reasonable!

One improvement would be making access more safe and explicit. Another would be, potentially, tracking this number more correctly in the parallel backfill worker (or some other shared code), which would more correctly track the lowest outstanding partially-processed sequence number; as-is, there are multiple threads processing events, and some threads might be behind.

From what I understand it seems you should look at the sync/atomic functions (or use a mutex).

Indeed! We used atomics for this in #560

Thanks for the note