[
https://issues.apache.org/jira/browse/IMAP-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13632687#comment-13632687
]
Andrzej Rusin commented on IMAP-372:
------------------------------------
Hi Ioan,
Here is already a defensive scenario by copying the listeners into a new
ArrayList, which is a local variable and cannot be touched from outside.
Because of that I think that immutable objects in this particular place would
only add overhead without noticeable gain.
Hi Eric.
The code is running under high traffic for days already without a deadlock.
This does not really mean much, as it was running without the fix for years
without problems, and then deadlocked two times in one day.
As for deadlock scenario, it is quite simple:
1. Some event happens, AbstractDelegatingMailboxListener.event gets called,
thread A obtains a lock on the listeners HashMap inside it
2. Concurrently, some client logs out, thread B processes
SelectedMailboxImpl.deselect, obtains a lock on SelectedMailboxImpl instance by
means of synchronized method deselect
Then:
Thread A wants a lock on the SelectedMailboxImpl instance on the (synchronized)
msn method, but it's held by thread B
Thread B wants a lock on listeners HashMap in removeListener method, but it's
held by thread A.
So we have a deadlock.
Thread A is the second from the top thread in "James Listener Deadlock.txt",
thread B is the third. The first thread in that file does not cause the
deadlock, it only suffers from that.
> Deadlock in AbstractDelegatingMailboxListener under load
> --------------------------------------------------------
>
> Key: IMAP-372
> URL: https://issues.apache.org/jira/browse/IMAP-372
> Project: James Imap
> Issue Type: Bug
> Components: Mailbox
> Reporter: Andrzej Rusin
> Assignee: Eric Charles
> Attachments: James Listener Deadlock.txt
>
>
> In AbstractDelegatingMailboxListener::event, firing the events inside the
> synchronized blocks causes a deadlock involving:
> lock on HashMapDelegatingMailboxListener::listeners
> (synchronized methods) lock on SelectedMailboxImpl
> In my example, these 3 methods got interlocked:
> AbstractDelegatingMailboxListener.addListener
> SelectedMailboxImpl.msn
> AbstractDelegatingMailboxListener.removeListener
> My idea to fix it is basically to take the for loop on mListeners outside the
> synchronized block in
> org.apache.james.mailbox.store.AbstractDelegatingMailboxListener.event(Event).
> That will not make the propagated event processing in SelectedMailboxImpl
> hit the synchronized lock on listeners.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]