Bug #2137
Bad invalidation of good resource in concurrency situation
Start date:
02.08.2022
Due date:
% Done:
0%
Estimated time:
origin:
Description
The code in com.zfabrik.impl.resources.NamespaceImpl._getResourceHandleImplNonNull(String) may run into a concurrency situation, where a collected resource handle leads to a repeated tick() and invq adding and then invalidation of a concurrently just newly created resource.
Example¶
- Threads T1, T2.
- Resource name N
Flow:
- T1: lookup for N returns value holder with null resource handle.
- T1: Goes into looping = true
- T1: leaves synchronized block
- T2: runs tick() and enters synchronized block
- T2: Creates and adds new resource handle
- T2: leaves synchronized block
- T1: enters synchronized block again
- T1: finds that it is looping and the value holder for N is not in the invQ and hence puts it into invQ (although the resource handle is NOT null anymore!!!)
- T1: invalidates the resource for N right away
Acceptance Criteria¶
- When looping for pending invalidations make sure not to accidentally consider a valid non-null handle as to be invalidated
Test Cases¶
- com.zfabrik.test.core.resources.tests.Invalidations.concurrentLookupOfCollectedResource: Concurrent lookup and GCing on weakly held resource.