Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 228962

Summary: Threading flaw with org.eclipse.emf.transaction.util.Lock
Product: [Modeling] EMF Services Reporter: Min Idzelis <min123>
Component: TransactionAssignee: Boris Gruschko <boris.gruschko>
Status: CLOSED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: ahunter.eclipse, jlescot
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 283446    
Bug Blocks:    

Description Min Idzelis CLA 2008-04-25 17:57:30 EDT
Build ID: Eclipse 3.4M6a

Steps To Reproduce:
in uiSafeAcquire() the following code is used:

  final Job currentJob = jobmgr.currentJob();
        final ISchedulingRule jobRule;
        if ((currentJob != null) && (currentJob.getRule() != null)) {
            // running as a job on a scheduling rule? Cannot use
            // JobManager.beginRule() to show the "UI blocked" dialog
            jobRule = null;
        } else {
            jobRule = new AcquireRule();
        }

This is used to determine if a Job can be used to acquire the lock. It turns out the currentJob().getRule() may return null when there is a Job active, but it has no rule set on it. Instead, the a rule was acquired within the run() method of the job by using JobManager.beginRule(). 

I think the only way to solve this is to request API from JobManager to get the active "ruleStack" for the current Thread. 

A test case not ready yet, but is pending. When it's ready it will be attached to this bug. 


More information:
Comment 1 Jacques LESCOT CLA 2008-04-29 04:30:59 EDT
Retargeting the right Product/Component
Comment 2 Christian Damus CLA 2008-08-26 13:51:01 EDT
David, shall I assume that you don't want to fix this bug? (I didn't notice it, sooner, because it is still assigned to you)
Comment 3 Jacques LESCOT CLA 2008-08-27 03:05:52 EDT
Initially the bug was open against EMFT Ecore Tools component and was assigned to David by default. While retargeting to EMF Transaction, I did not noticed that David was still assigned, so you were right while reassigning it.
Comment 4 Boris Gruschko CLA 2009-07-14 13:22:10 EDT
Hi Min,

If I understand the issue correctly, the fix for 262175 should fix this issue too. 

Can you confirm this ?

Thanks in advance,
Boris
Comment 5 Min Idzelis CLA 2009-07-14 14:10:22 EDT
Yes. This bug seems like a dup of bug 262175. The fix over there should also fix this bug. However, the fix seems a bit excessive. Now the UI will hang anytime any job or any thread with beginRule() has invoked acquire on the ILock. Ideally, we need to get the rule stack associated for the active thread, and see if any one of those rules is non-null, not just the "currentJob". 

I've opened up bug 283446 to track the ability to get the active rule stack. 

Comment 6 Anthony Hunter CLA 2010-02-08 13:46:40 EST
(In reply to comment #5)
> Yes. This bug seems like a dup of bug 262175. The fix over there should also
> fix this bug. [...]

Can you confirm this was indeed the case, that this issue no longer exists for you?
Comment 7 Min Idzelis CLA 2010-04-05 17:52:12 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > Yes. This bug seems like a dup of bug 262175. The fix over there should also
> > fix this bug. [...]
> 
> Can you confirm this was indeed the case, that this issue no longer exists for
> you?

This issue still does exist. Since it is possible to get the rules started within a Job with a null scheduling rule this should be easily fixable. 

See Job.getJobManager().currentRule() 

this should replace the existing code at line 276 in Lock.java:

        final Job currentJob = jobmgr.currentJob();
        final ISchedulingRule jobRule;
        if (currentJob != null) {
            // running as a job? Cannot use JobManager.beginRule() to show the
        	// "UI blocked" dialog
            jobRule = null;
        } else {
            jobRule = new AcquireRule();
        }
Comment 8 Anthony Hunter CLA 2010-04-05 18:03:03 EDT
This is a duplicate of Bug 306987 that has been fixed in Helios M7 (last week in fact).

*** This bug has been marked as a duplicate of bug 306987 ***