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 232085 - Events are fired while DataObjectPool is in 'atomic' state
Summary: Events are fired while DataObjectPool is in 'atomic' state
Status: NEW
Alias: None
Product: platform
Classification: Unclassified
Component: Data Systems (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal (vote)
Assignee: Jaroslav Havlin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-01 14:09 UTC by Svata Dedic
Modified: 2013-11-13 13:51 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Possible fix (4.89 KB, patch)
2013-11-13 13:51 UTC, Jaroslav Havlin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Svata Dedic 2013-07-01 14:09:43 UTC
See issue #122257.

DataNode nodeDestroyed event is *sometimes* fired synchronously while the DataObjectPool is in 'atomic' state (its atomic variable is set to current thread). 

The code reacting in EDT to the node event in issue #122257 caused a DataEditorSupport.openDocument() call, which eventually run prepareDocument and tried to open the document in another thread B, waiting for the result. The thread B required DataObject access, but DataObject.find() blocked in enterRecognition on the atomic action not finished in EDT.

The fix in #122257 was to pre-fetch encoding in DataEditorSupport.openDocument to avoid executing the query in document loading code.

The fix contributes to issue #216679 and I think the fix could be made in a different way - the reason for the deadlock is not primarily the FEncQuery, but execution of a listener chain while DataObjectPool is in a restricted state.

A simple fix would be to offload DataNode fireNodeDestroyed to a request processor, so that the DataObject.dispose() and call above it complete, unlock the DataObjectPool. A potential thread B then can proceed with DataObjectPool access to find out document encoding and load it. The code in DataEditor.openDocument can be removed, which breaks condition leading to #216679 and may improve performance - FEQ will be run only when actually reading the stream, not when openDocument() is called on an already opened editor.

More elaborate fix would postpone the DataObject.firePropertyChange(PROP_VALID) until after the DataObjectPool.runAtomicAction completes. This could be done inside DataSystems module wihtout changing API and even without changing the thread assignment of operations as in the 1st fix alternative above. A brutal solution would be to queue all events fired from DataObject.firePropertyChange until after DataObjectPool.runAtomic completes. Still not 100% safe, since setValid and dispose() are not final and could potentially extend the DataObjectPool lock in an unexpected way.
Comment 1 Jaroslav Havlin 2013-11-13 13:51:17 UTC
Created attachment 142133 [details]
Possible fix

> More elaborate fix would postpone the DataObject.firePropertyChange(PROP_VALID) 
> until after the DataObjectPool.runAtomicAction completes.
DataObject.setValid(boolean) uses a vetoable change event for property
PROP_VALID, so it needs to be fired immediately.

> A simple fix would be to offload DataNode fireNodeDestroyed to a request 
> processor, so that the DataObject.dispose() and call above it complete, unlock 
> the DataObjectPool.
The NodeDestroyed change can fired later in EDT. Please check the attached patch.
(I've also tried to fire all events asynchronously, but it made some tests fail.)
Thank you.