I'm working on updating ssb-replication-scheduler to use the new API in ssb-meta-feeds, and in the tests there are some cases of index feeds that are created at the same time.
Problem
If two findOrCreate calls happen concurrently ("at the same time"), then both calls may create a "v1" feed under the root, which leads to a situation like
graph TB;
root --> v1a[v1] & v1b[v1]
This can also happen with shard feeds and leaf feeds.
Also, this concurrency problem can happen with findAndTombstone: there should be only one metafeed/tombstone message for a given subfeed.
Solution
Use mutexify in findOrCreate and findAndTombstone to enforce that only one call can happen at a time. I was working on a more complex solution before, which would allow concurrency if you're creating unrelated feeds like root/v1/7/chess and root/v1/7/tictactoe, but I realized that subfeed creation doesn't have to be efficient (we're not going to be creating feeds at a high throughput), so I went with the nuclear (and simpler) solution of allowing only one findOrCreate at a time, no matter what the arguments are.
Context
I'm working on updating ssb-replication-scheduler to use the new API in ssb-meta-feeds, and in the tests there are some cases of index feeds that are created at the same time.
Problem
If two
findOrCreate
calls happen concurrently ("at the same time"), then both calls may create a "v1" feed under the root, which leads to a situation likeThis can also happen with shard feeds and leaf feeds.
Also, this concurrency problem can happen with
findAndTombstone
: there should be only onemetafeed/tombstone
message for a given subfeed.Solution
Use
mutexify
infindOrCreate
andfindAndTombstone
to enforce that only one call can happen at a time. I was working on a more complex solution before, which would allow concurrency if you're creating unrelated feeds likeroot/v1/7/chess
androot/v1/7/tictactoe
, but I realized that subfeed creation doesn't have to be efficient (we're not going to be creating feeds at a high throughput), so I went with the nuclear (and simpler) solution of allowing only onefindOrCreate
at a time, no matter what the arguments are.1st :x: 2nd :heavy_check_mark: