[YANGTOOLS-268] Fix synchronization issues in InMemoryDataTree Created: 18/Aug/14  Updated: 10/Apr/22  Resolved: 04/Sep/14

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Tom Pantelis Assignee: Tom Pantelis
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 1570

 Description   

There's a couple issues in InMemoryDataTree wrt to synchronization:

1) There's redundant synchronization in the setSchemaContext, validate, prepare and commit methods, ie the methods are both synchronized and they use the read/write lock. The synchronized keyword should be removed (it's not good practice anyway to synchronize methods). I suspect the read/write lock was added afterwards and the person forgot to remove synchronized.

2) The validate method accesses the 'rootNode' member completely unsynchronized. This is unsafe - all accesses to 'rootNode' must be synchronized wrt to one another. Since validate doesn't modify the 'rootNode' it can acquire the read lock. It passes 'rootNode' to another class and I don't think we need to hold the lock across that call so we should be able to do:

TreeNode localRootNode;
rwLock.readLock().lock();
try

{ localRootNode = rootNode; }

finally

{ rwLock.readLock().unlock(); }

m.getStrategy().checkApplicable(..., Optional.<TreeNode>of(localRootNode));



 Comments   
Comment by Tom Pantelis [ 21/Aug/14 ]

Submitted https://git.opendaylight.org/gerrit/#/c/10122/.

Generated at Wed Feb 07 20:52:44 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.