Bug 305833 - Dead Lock in DeltaProcessor.resourceChanged
Summary: Dead Lock in DeltaProcessor.resourceChanged
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows Vista
: P3 major with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 249951
Blocks:
  Show dependency tree
 
Reported: 2010-03-15 06:55 EDT by Jens Baumgart CLA
Modified: 2019-11-02 19:17 EDT (History)
4 users (show)

See Also:


Attachments
Stack Trace (6.61 KB, text/plain)
2010-03-15 06:58 EDT, Jens Baumgart CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Baumgart CLA 2010-03-15 06:55:46 EDT
Build Identifier: Eclipse 3.5.1

In our scenario a dead lock with DeltaProcessor.resourceChanged occurs (see attached stack trace). 
Thread Worker-0 owns the OrderedLock and calls JavaProject.resolveClasspath.
Our class path container (RequiredDcsClasspathContainer) waits for a lock (DevConf Lock).
Thread ModalContext owns WorkspaceRoot and DevConf Lok and waits for OrderedLock.
=> Dead Lock

I think it is problematic to call client code (class path container) when holding OrderedLock.


Reproducible: Sometimes
Comment 1 Jens Baumgart CLA 2010-03-15 06:58:12 EDT
Created attachment 162031 [details]
Stack Trace
Comment 2 Xu XIANG CLA 2010-03-18 10:43:39 EDT
see similar deadlocks Bug 291764, Bug 292404
Comment 3 Jay Arthanareeswaran CLA 2010-04-12 05:12:48 EDT
The DeltaProcessor#resourceChanged (and eventually IClasspathContainer#getClasspathEntries) is running inside the notification thread and other threads are not allowed to modify the workspace during the resource change event. JDT/Core needs to resolve the classpath container during this event. Just wondering, in the other thread, can't you check if the workspace tree is locked or not and proceed with the modify operation?
Comment 4 Jens Baumgart CLA 2010-04-12 07:42:34 EDT
(In reply to comment #3)
> The DeltaProcessor#resourceChanged (and eventually
> IClasspathContainer#getClasspathEntries) is running inside the notification
> thread and other threads are not allowed to modify the workspace during the
> resource change event. JDT/Core needs to resolve the classpath container during
> this event. Just wondering, in the other thread, can't you check if the
> workspace tree is locked or not and proceed with the modify operation?

This would mean I would have to release DevConf Lock in ModalContext if the tree is locked.
This would be somehow strange for me to release a lock that was aquired some stack frames above.
I think the root cause of the issue is calling client code inside OrderedLock. Any client code using locks might get this problem.
Would it be possible to perform the work of 
DeltaProcessingState.resourceChanged in a separate Job to get out of the OrderedLock issue?
Comment 5 Jens Baumgart CLA 2010-04-12 07:58:20 EDT
Just for clarification: DevConf lock protects read and write access of our data structure.
The only thing we could do in our class path container is to check if the tree is locked and then not to aquire our lock and not to return our class path.
But I think this would be no good solution.
Comment 6 Jay Arthanareeswaran CLA 2010-04-12 09:19:27 EDT
(In reply to comment #4)
> I think the root cause of the issue is calling client code inside OrderedLock.
> Any client code using locks might get this problem.
> Would it be possible to perform the work of 
> DeltaProcessingState.resourceChanged in a separate Job to get out of the
> OrderedLock issue?

Well, I did think about that. But that would be a significant change. I will investigate, though.
Comment 7 Jay Arthanareeswaran CLA 2010-04-22 09:47:22 EDT
Dani,

This fix might require moving all the code that reacts to a resource change and a subsequent classpath resolution be moved to a separate job to avoid the deadlock. At this stage such a change might pose considerable risks.

What is your opinion?
Comment 8 Dani Megert CLA 2010-04-22 11:40:38 EDT
(In reply to comment #7)
> Dani,
> 
> This fix might require moving all the code that reacts to a resource change and
> a subsequent classpath resolution be moved to a separate job to avoid the
> deadlock. At this stage such a change might pose considerable risks.
> 
> What is your opinion?

Such a change is definitely out of scope for 3.6 and we'd first have to investigate and understand that this is the right solution.
Comment 9 Dani Megert CLA 2010-04-22 11:42:32 EDT
Also note that it's possible to resolve the issue on the client side (Bug 291764, Bug 292404).
Comment 10 Jens Baumgart CLA 2010-04-23 04:12:46 EDT
Hi Dani,

I do not know how I should fix this. ModalContext already has /R and our lock that protects our data structure (DevConf). Access to a resource causes ModalContext to wait for OrderedLock:

ModalContext
	has /R
	has DevConf Lock
	waits for OrderedLock

Thread Worker-0 is broadcasting changes. JDT calls our class path container (CPC).
Our CPC has 2 options to avoid the dead lock:

1. Access our data structure without DevConf lock. This would introduce a race condition.

2. Return an empty classpath. This would break our clients.

Worker 0
	has OrderedLock
	waits for DevConf Lock

Our component itself is a big framework with lots of tools on top.

Again I think it is very problematic that JDT calls client code while owning the OrderedLock.
Comment 11 Dani Megert CLA 2010-04-23 04:21:53 EDT
I didn't look deeply into how you could fix this but given the other similar cases could get fixed on the client side I'd assume it's possible here as well.

>Again I think it is very problematic that JDT calls client code while owning
>the OrderedLock
We do this for a long time now. I don't say it's perfect but definitely not something we are going to change so late in the 3.6 cycle.
Comment 12 James Blackburn CLA 2011-05-03 13:03:08 EDT
We should be able to fix this in core.resources - it shouldn't hold the ws lock while firing the resource delta.
Comment 13 Eclipse Genie CLA 2019-11-02 19:17:32 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.