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

SynchronizationLockException in user-defined mailboxes #3459

Closed
Aaronontheweb opened this issue May 22, 2018 · 1 comment · Fixed by #3467
Closed

SynchronizationLockException in user-defined mailboxes #3459

Aaronontheweb opened this issue May 22, 2018 · 1 comment · Fixed by #3467
Assignees
Milestone

Comments

@Aaronontheweb
Copy link
Member

Akka.NET Version: Unknown

Found an issue reported by an end-user on StackOverflow: https://stackoverflow.com/questions/50292073/synchronizationlockexception-in-akka-net-mailboxes

They're using a custom mailbox

public class MyActorMailBox: UnboundedPriorityMailbox
{
    public MyActorMailBox(Settings settings, Config config) : base(settings, config)
    {}

    protected override int PriorityGenerator(object message)
    {
        if (message is MyActorMailBox.ErroredMessage)
            return 0;
        return 1;
    }
}

Configured with the following HOCON:

  <!-- language: lang-xml -->
  <akka>
    <hocon>
      <![CDATA[
      akka
      {...}
      myactor-mailbox
      {     
         mailbox-type="MyActorMailBox, MyNamespace"
      }
      ]]>
    </hocon>
  </akka>

And initialized with the following code:

  ActorSystem.ActorOf(
        Props.Create(() => new MyActor()).WithMailbox("myactor-mailbox"), "MyActor");

Which throws the following exception:

Swallowing exception during message send
System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code.
   at Akka.Dispatch.MessageQueues.BlockingMessageQueue.Enqueue(IActorRef receiver, Envelope envelope)
   at Akka.Dispatch.MessageDispatcher.Dispatch(ActorCell cell, Envelope envelope)
   at Akka.Actor.ActorCell.SendMessage(Envelope message)

Need to determine why this is being thrown and under what version of Akka.NET this occurs.

@Aaronontheweb
Copy link
Member Author

Ok, figured this one out.

Looks like we're not checking to see if the TryEnter method succeeds or not when we move onto the next operation:

public int Count
{
get
{
Monitor.TryEnter(_lock, BlockTimeOut);
try
{
return LockedCount;
}
finally
{
Monitor.Exit(_lock);
}
}
}

We need to do a check to see if the lock entry failed or succeeded, given that the queue is blocking. If the lock entry timed out, we need to do something other than try to enter. This is a bug.

@Aaronontheweb Aaronontheweb added this to the 1.3.8 milestone May 24, 2018
Aaronontheweb added a commit to Aaronontheweb/akka.net that referenced this issue May 24, 2018
cuteant pushed a commit to cuteant/akka.net that referenced this issue Jun 1, 2018
…kadotnet#1544

* fixed RemoteActorRef.GetChild

* fixed the first set of issues related to akkadotnet#1544

* close akkadotnet#3459 - just block until lock is available inside BlockingQueue

* close akkadotnet#3450 - don't let SplitBrainResolver log 'partition detected' messages when there are no unreachable nodes

* close akkadotnet#3420 - verified that wildcard ActorSelections actually do get delivered to deadletters when there's no matching recipient
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant