#8587·cadence

TestListDomains flakes with expected: 2 actual: 3 due to Cassandra domain-store orphan race

Author: c-warrenCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugtriage/needs-info

What test is failing? host/persistence/cassandra → TestCassandraDomainPersistence/TestListDomains

Failure metadataPersistenceV2Test.go:1358: Not equal: expected: 2 actual: 3. TestListDomains asserts an exact count of all domains returned by ListDomains, and an extra, orphaned domain shows up. Observed in CI run: https://github.com/cadence-workflow/cadence/actions/runs/31034914206 (job "history queue v2 with alert").

Root cause The orphan is left behind by TestConcurrentCreateDomain, which runs earlier in the same suite and drives heavy contention on domain creation:

  • InsertDomain (common/persistence/nosql/nosqlplugin/cassandra/domain.go, ~line 123-135) unconditionally deletes the by-ID domains row whenever the batch CAS is not applied, before checking whether the failure was actually a "name already exists" case. This delete races with a sibling goroutine's re-insert of the same row, and under contention can leave a domains_by_name_v2 (by-name) row with no matching domains (by-ID) row.
  • The test suite's per-test cleanup deletes domains by ID, and DeleteDomain silently returns nil when the by-ID row is already missing, so the orphaned by-name row survives every cleanup until TestListDomains counts it.

Evidence

  • CI run 31034914206, commit 1f9180688, job "history queue v2 with alert": the log shows Domain already exists for a domain name during TestConcurrentCreateDomain, a branch only reachable when the by-name row exists but the by-ID row does not. That's direct evidence the orphan state occurred mid-run.
  • This passes on subsequent CI jobs indicating that this is a flake.

Suggested fix

  • In InsertDomain's not-applied path, inspect the CAS previous rows before deleting the by-ID row, and skip the delete when the by-name row already holds the same domain ID (that by-ID row is a repair, not something to clean up).
  • Alternatively, have the test suite's cleanup delete by name (not just by ID) so an orphaned by-name row actually gets removed between tests.

Acceptance criteria

  • Concurrent domain creation under CAS contention cannot leave an orphaned domains_by_name_v2 row.
  • TestListDomains no longer flakes due to leftover domains from TestConcurrentCreateDomain.

Source: cadence-workflow/cadence