The current implementation has changes to reduce lock contention. However, the tests outside of the lock statement can throw exceptions if they execute while the work inside the lock statement is processing on a separate thread.
This bug was introduced by https://github.com/couchbase/couchbase-net-client/commit/0b7d32205d5ff45eef42bf46318e67489324eee0 in 2.7.12
- Should use .Count instead of .Any(), which is thread-safe. Any enumerates the collection, which will cause an exception if the collection is mutated
- Within the lock, the field shouldn't be assigned until after the collection is fully built
Side note: Using "list.Count != 0" is actually more performant than "list.Any()" prior to .NET 5 because it avoids building an enumerator (https://github.com/dotnet/corefx/pull/40377)