Skip to content
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

Fix address terminated topic atomic updates (#4306) #4307

Conversation

petrikero
Copy link
Contributor

Submitting PR against v1.3, as that's what we're using and I was able to test the fix with.

The new implementation fixes both the race condition as well as optimizes the full copies of the _subscribers HashSet during Subscribe() and Unsubscribe(). The updates are protected with locks which makes the code simple and efficient. Publish() only takes a copy under lock to minimize the amount that the data is not available for other threads, which should be ok, as Publish() is only needed when a node is lost, so not too frequently.

…mize the implementation to not take copies on Subscribe() or Unsubscribe().
Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -35,7 +37,7 @@ public override AddressTerminatedTopic CreateExtension(ExtendedActorSystem syste
/// </summary>
internal sealed class AddressTerminatedTopic : IExtension
{
private readonly AtomicReference<HashSet<IActorRef>> _subscribers = new AtomicReference<HashSet<IActorRef>>(new HashSet<IActorRef>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another ancient bug - looks like we tried to get too cute by half here. I agree that a lock should be a relatively simple fix for this.

@Aaronontheweb Aaronontheweb linked an issue Mar 9, 2020 that may be closed by this pull request
@Aaronontheweb Aaronontheweb merged commit da53e08 into akkadotnet:v1.3 Mar 9, 2020
@petrikero petrikero deleted the fix-address-terminated-topic-atomic-updates branch March 9, 2020 20:54
Aaronontheweb pushed a commit to Aaronontheweb/akka.net that referenced this pull request Mar 9, 2020
…mize the implementation to not take copies on Subscribe() or Unsubscribe(). (akkadotnet#4307)
Aaronontheweb added a commit that referenced this pull request Mar 10, 2020
…mize the implementation to not take copies on Subscribe() or Unsubscribe(). (#4307) (#4309)

Co-authored-by: Petri Kero <petrikero2@gmail.com>
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.

Atomicity bug and bad performance in AddressTerminatedTopic
2 participants