This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 37432 - Deadlock in CloneableEditorSupport.closeDocument
Summary: Deadlock in CloneableEditorSupport.closeDocument
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 3.x
Hardware: PC Linux
: P3 blocker (vote)
Assignee: Petr Nejedly
URL:
Keywords: RANDOM, THREAD
Depends on:
Blocks:
 
Reported: 2003-11-22 16:14 UTC by Jesse Glick
Modified: 2008-12-22 22:41 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump (11.34 KB, text/plain)
2003-11-22 16:15 UTC, Jesse Glick
Details
Possible fix (1.57 KB, patch)
2003-11-25 15:41 UTC, Miloslav Metelka
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2003-11-22 16:14:08 UTC
Probably unreproducible, and the thread dump
doesn't make any sense to me.
Comment 1 Jesse Glick 2003-11-22 16:15:11 UTC
Created attachment 12268 [details]
Thread dump
Comment 2 Jesse Glick 2003-11-22 16:16:32 UTC
BTW: current dev build; I was closing several documents by pressing
Ctrl-F4 repeatedly. It it matters, is possible that the one I was
about to close had been externally modified and was due to be reloaded.
Comment 3 Petr Nejedly 2003-11-24 08:17:30 UTC
The dump is a bit of mystery for me either.
It seems the JDK have misreported the locks held, so the dump should
look like:
"AWT-EventQueue-1" prio=1 tid=0x08367590 nid=0x6bc3 runnable
oot.CloneableEditorSupport.closeDocument(CloneableEditorSupport.java:1391)
- relocked lock <0x46ce9358> (oow.CloneableOpenSupport$Listener)
oot.CloneableEditorSupport.notifyClosed(CloneableEditorSupport.java:1244)
oot.DataEditorSupport.notifyClosed(DataEditorSupport.java:217)
oot.EditorSupport$Del.superNotifyClosed(EditorSupport.java:551)
oot.EditorSupport.notifyClosed(EditorSupport.java:426)
onm.java.JavaEditor.notifyClosed(JavaEditor.java:271)
- locked <0x46ce9358> (a oow.CloneableOpenSupport$Listener)
oot.EditorSupport$Del.notifyClosed(EditorSupport.java:536)

The lock is already held by the thread, so reenter should be seamless.
Moreover, the thread is (acc. to line number) already inside the sync
section, just calling openDocumentImpl()
(so the external modification status matters!)

Finally, the thread is marked as runnable so it should (in the next
CPU tick) enter the oDImpl method.

Random thought: Was it really deadlocked? (i.e. no CPU activity
and the dump was the same several times?)
(Can it be an infinite loop instead? ;-)

Huh, now I see it. It *IS* infinite loop...
Comment 4 Petr Nejedly 2003-11-24 08:21:14 UTC
More details:
The AWT queue spin-waits for the document to be loaded, but keeps the
lock, so it can't be loaded. Two bad things:
1. Doesn't release the lock so the loading can't proceed
2. It spins!
Comment 5 Petr Nejedly 2003-11-25 12:20:37 UTC
Hard to cut this one:
I can:
A) either replan the actual closing task, which would mean the close()
call would finish before actually closing (the reload will happen
after the call, and then the real close would take place).
B) or I can move the lock inside the loop, which would keep spinning
and racing for the lock with the reload task
C) I could also alter the state machine to perform the real close
under the lock before reloading and let the reload task recognize such
state as soon as it finally acquires the lock.
The reload task would know it is irrelevant and give up.

C) seems the best.

CCing Mila, who wrote the state machine.
Comment 6 Miloslav Metelka 2003-11-25 15:40:34 UTC
Yes, I agree with C as well. The thread doing document closing should
change the state to closed and the reloading task must check state
right after acquiring the lock. I'm attaching a diff of the possible
fix but I did not test it at all. Just an idea.
Comment 7 Miloslav Metelka 2003-11-25 15:41:59 UTC
Created attachment 12292 [details]
Possible fix
Comment 8 Petr Nejedly 2003-11-26 14:10:35 UTC
OK, I applied the fix and tested it thoroughly. It seems OK to me and
to the tests. 
Comment 9 Miloslav Metelka 2003-11-26 14:52:18 UTC
Petre, thanks a lot for applying and testing the patch.
Comment 10 Marian Mirilovic 2005-07-13 13:24:19 UTC
closed