Skip to content

Fix initialization retry and concurrent completion semantics (#85) - #98

Draft
AGiorgetti wants to merge 3 commits into
developfrom
feature/fix-initialization-retry-85
Draft

AGiorgetti wants to merge 3 commits into
developfrom
feature/fix-initialization-retry-85

Conversation

@AGiorgetti

@AGiorgetti AGiorgetti commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Scope

Addresses #85 independently of #87 and #86, based directly on develop 286c0ae.

  • Share one initialization attempt so concurrent callers wait for the same success or exception.
  • Retain successful initialization only after all existing index and checkpoint-generator setup completes.
  • Allow a later call to retry a failed attempt.
  • Reject same-thread recursive initialization before it can poison the shared attempt.
  • Keep setup logic, exception mapping, index definitions and dependencies unchanged. Initialize is synchronous; no async initialization API is added.

Tests first

The first commit, 75ddea0, contains only permanent regression tests.
Against unchanged product code on MongoDB 7.0.45 / net8.0: 5 failed, 1 passed, 0 skipped.

Six scenarios cover real index-conflict retry, checkpoint-constructor failure after indexes succeed, successful idempotence, gated concurrent success/failure, and caught recursive entry. Concurrent waiters must observe the same failed attempt rather than silently starting a retry. Tests use gates and thread state, not a timing benchmark, and follow Context/Because/Fact conventions.

The recursion regression also caught and rejected an intermediate implementation that could poison Lazy state; the final guard passes it.

Final local validation

Exact published tree: 399ca0fd95914fdfb87c57970e9223001555e90e.

  • Whole solution Release build, including net472: 0 errors, 296 warnings (including existing dependency audit warnings).
  • Each of net8.0/net9.0/net10.0: 6 focused tests passed; 536 core tests passed; 225 adapter tests passed, 1 unchanged known baseline [P2] Exact-ID explain assertion rejects MongoDB 7 IDHACK despite using the _id index #94 failure; 0 skipped.
  • The only adapter failure is Stream_head_delete_by_id_should_use_the_builtin_id_index, the existing IDHACK query-plan portability assertion. No test was suppressed or weakened.
  • Focused command: dotnet test src/NEventStore.Persistence.MongoDB.Tests/NEventStore.Persistence.MongoDB.Core.Tests.csproj -c Release -f net8.0 --filter FullyQualifiedName~Issue_85
  • Independent review found no remaining findings in the final initialization guard and tests.

Local database: MongoDB 7.0.45. MongoDB 8 cannot start on this cloud host because required /sys CPU metadata is unavailable; PR CI uses MongoDB 8. net472 was compiled, not executed on Linux. No timing benchmarks. No package, workflow or unrelated fix changes.

Exact-head GitHub CI

CI run 39969206709 succeeded on head 3fb5929: Ubuntu and Windows builds and all MongoDB 8 Linux net8.0/net9.0/net10.0 test jobs passed. No reruns were needed.

Draft for user review; do not merge or publish packages.

Co-authored by Alessandro Giorgetti and Codex (OpenAI).

On unchanged product code: 5 failing regressions, 1 passing idempotence test.
Cover index/checkpoint setup, shared concurrent outcomes, and recursive entry.

Co-authored by Alessandro Giorgetti and Codex (OpenAI).
Publish success after setup, let concurrent callers join the same attempt,
and reject recursive initialization without poisoning a running attempt.

Co-authored by Alessandro Giorgetti and Codex (OpenAI).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant