go-ipld-format icon indicating copy to clipboard operation
go-ipld-format copied to clipboard

Batch is not thread safe

Open hsanjuan opened this issue 7 years ago • 2 comments

Looking at batch code, it using an activeCommits int and size int counters very liberally all over the place. Calling Add(), at the same time as Commit() seems likely to trigger weird side effects: i.e. size reset to 0 when it should not, or activeCommits potentially going on the negative.

hsanjuan avatar Oct 25 '18 14:10 hsanjuan

Batch was never intended to be thread-safe. We should probably document that.

We could also just make it thread-safe. Given that we have to spin off goroutines anyways, that may not be a bad idea.

For context, batch used to be extremely simple and flushed synchronously. We had to change that to prevent periodic pauses on add.

Stebalien avatar Oct 25 '18 16:10 Stebalien

I'll add a note for the moment

hsanjuan avatar Oct 25 '18 17:10 hsanjuan