-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fixed race condition with creating priority queue #2447
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
fixed race condition with creating priority queue #2447
Conversation
@@ -2614,6 +2614,8 @@ namespace Akka.Dispatch.MessageQueues | |||
} | |||
public class UnboundedPriorityMessageQueue : Akka.Dispatch.MessageQueues.BlockingMessageQueue | |||
{ | |||
[System.ObsoleteAttribute("Use UnboundedPriorityMessageQueue(Func<object, int> priorityGenerator, int initia" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked all of the methods that don't have you explicitly set the priorityGenerator
at construction time as obsolete.
@@ -4853,14 +4855,17 @@ namespace Akka.Util | |||
public override bool IsRight { get; } | |||
public TA Value { get; } | |||
} | |||
public class ListPriorityQueue | |||
public sealed class ListPriorityQueue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no really means for extending this queue given that all of the important parts of it are private fields.
@@ -12,63 +12,63 @@ | |||
namespace Akka.Dispatch.MessageQueues | |||
{ | |||
/// <summary> | |||
/// Base class message queue that uses a priority generator for messages | |||
/// Base class for a message queue that uses a priority generator for messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to fill in all of the TBDs that @sean-gilliam left as placeholders.
{ | ||
_data = new List<Envelope>(initialCapacity); | ||
_priorityCalculator = priorityCalculator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set all of the guts of the priority queue in the same place...
{ | ||
_prioQueue.SetPriorityCalculator(priorityGenerator); | ||
_prioQueue = new ListPriorityQueue(initialCapacity, priorityGenerator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key fix: create the queue WITH its priority generator at the same time and never change it again. That way we don't end up in a situation where the mailbox is having messages queued into it while the underlying priority generator is being changed concurrently on another thread.
close #2308 - realized that this was the result of a weird design choice on my part back when we were working on releasing 1.1. Should never change the priority generator function at runtime. Now it's set via a constructor and is immutable, which should eliminate the issue.
CC @ronnieoverby