Skip to content

Multiple ReadJournal instances cause actor name conflicts and incorrect query throttling #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aaronontheweb opened this issue Apr 6, 2025 · 0 comments
Labels
akka-persistence-query bug Something isn't working

Comments

@Aaronontheweb
Copy link
Member

Version Information
Version of Akka.NET? v1.5.40
Which Akka.NET Modules? Akka.Persistence.Sql

Problem Description

When running multiple persistence journals in the same Akka.NET application with Akka.Persistence.Sql, creating multiple ReadJournal instances causes actor name conflicts. This occurs when multiple projection actors (ReceivePersistentActor instances) try to create their own read journals using Context.System.ReadJournalFor<SqlReadJournal>().

Error Messages

Users encounter either of these exceptions:

  • Actor name "akka.persistence.query.journal.contact-query-permitter" is not unique\!
  • Actor name "journalakka-persistence-sql-sequence-actor" is not unique\!

Current Implementation Issues

  1. ReadJournal is being created multiple times unnecessarily
  2. Each ReadJournal creates its own query throttler, defeating the purpose of having a throttler in the first place
  3. The actors are created in the /user hierarchy instead of being /system actors

Reproduction Steps

  1. Create multiple persistence journals in the same Akka.NET application
  2. Use these journals for data projections to various destinations (SQL, RabbitMQ, etc.)
  3. Run multiple projector actors simultaneously
  4. When the second projection actor reaches its OnReplaySuccess() method and calls:
var readJournal = Context.System.ReadJournalFor<SqlReadJournal>("my-domain-name");

The exception is thrown.

Technical Details

Proposed Solutions

  1. Make the ReadJournal and query throttler singleton instances
  2. Move the actors to the /system hierarchy instead of /user
  3. Implement proper naming/scoping for these actors when multiple journals are in use

Impact

This issue affects anyone trying to run multiple projections simultaneously using Akka.Persistence.Sql, which is a common use case for data projections and event sourcing scenarios.

@Aaronontheweb Aaronontheweb added akka-persistence-query bug Something isn't working labels Apr 6, 2025
Arkatufus added a commit to Arkatufus/Akka.Persistence.Sql that referenced this issue Apr 7, 2025
Aaronontheweb pushed a commit that referenced this issue Apr 7, 2025
* Add #530 Spec

* Harden unit test

* Add comment block to explain SqlReadJournalProvider.GetReadJournal()

* Make all internal actors system actors

* Fix duplicate actor name issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
akka-persistence-query bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants