Open jwkosten opened 2 years ago
I also managed to witness this issue -- it appears to occur when AutoGC is set to 1 second (though I imagine it happens at any interval), and you are rapidly dequeuing records. Both Dequeue() and when the AutoGC fires go into the acquireDB method, causing this issue. A viable workaround is to not use AutoGC and just call Gc() once you're done dequeuing records.
That error is not limited to garbage collection (although can occur due to it as well). Can also be reliably reproduced just running a cycle of enqueue and dequeue in separate go routines:
go func() {
for {
queue.Enqueue([]byte("queue record"))
}
}()
go func() {
for {
queue.Dequeue()
}
}()
Although there is a per row lock when updating that map index.. There is no lock here on reading: https://github.com/jhunters/bigqueue/blob/v1.2.2/mmapfactory.go#L31 I think it's possible to get some kind of race condition here and indeed have a conflict on read and write for same index.
The issue persists because the locks are not properly acquired. I have a fixed version which completely removes the lockMap
which I don't think matters since opening DB is an operation of low frequency and will be amortized over operations.
Commit: https://github.com/jhunters/bigqueue/commit/5491f915fec6d4e9f244647d5fb776d8759f6237
I am getting a concurrency error while using this queue however it says that it is thread safe.
Attached are the logs from my app for context