spdx / Spdx-Java-Library

Java library which implements the Java object model for SPDX and provides useful helper functions
Apache License 2.0
37 stars 36 forks source link

Deadlock in ListedLicenseWebStore #250

Closed goneall closed 1 week ago

goneall commented 2 months ago

When fetching the license, a deadlock occurs at:

https://github.com/spdx/Spdx-Java-Library/blob/bb41916630c1eaf5ff5ec71d59cfbd6d303eeebc/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java#L352

due to a readlock being held in the call at: https://github.com/spdx/Spdx-Java-Library/blob/bb41916630c1eaf5ff5ec71d59cfbd6d303eeebc/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java#L305

Stack trace:

Thread [main] (Suspended)   
    owns: JsonLDDeserializer  (id=40)   
    Unsafe.park(boolean, long) line: not available [native method]  
    LockSupport.park(Object) line: 194  
    ReentrantReadWriteLock$NonfairSync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() line: 885    
    ReentrantReadWriteLock$NonfairSync(AbstractQueuedSynchronizer).acquireQueued(AbstractQueuedSynchronizer$Node, int) line: 917    
    ReentrantReadWriteLock$NonfairSync(AbstractQueuedSynchronizer).acquire(int) line: 1240  
    ReentrantReadWriteLock$WriteLock.lock() line: 959   
    SpdxListedLicenseWebStore(SpdxListedLicenseModelStore).fetchLicenseJson(String) line: 352   
    SpdxListedLicenseWebStore(SpdxListedLicenseModelStore).getPropertyValueDescriptors(String) line: 308    
    SpdxV3ListedLicenseModelStore.getPropertyValueDescriptors(String) line: 138 
    ModelCopyManager.copyCompatible(IModelStore, String, IModelStore, TypedValue, String, String) line: 300 
    ModelCopyManager.copy(IModelStore, String, IModelStore, String, String, String) line: 258   
    ModelCopyManager.copy(IModelStore, IModelStore, String, String, String) line: 423   
    JsonLDDeserializer.jsonStringToSpdxObject(JsonNode, String, Map<String,TypedValue>) line: 405   
    JsonLDDeserializer.jsonStringToStoredValue(String, JsonNode, String, Map<String,TypedValue>) line: 363  
    JsonLDDeserializer.toStoredObject(String, JsonNode, String, Map<String,String>, Map<String,TypedValue>) line: 341   
    JsonLDDeserializer.deserializeCoreObject(JsonNode, String, Map<String,String>, Map<String,TypedValue>) line: 241    
    JsonLDDeserializer.deserializeGraph(JsonNode) line: 129 
    JsonLDStore.deSerialize(InputStream, boolean) line: 149 
    JsonLDStore.deSerialize(InputStream, boolean) line: 52  
    SpdxToolsHelper.deserializeFile(ISerializableModelStore, File) line: 300    
    SpdxToolsHelper.readDocumentFromFileV3(ISerializableModelStore, File) line: 341 
    SpdxToolsHelper.readDocumentFromFile(ISerializableModelStore, File) line: 356   
    Verify.verify(String, SerFileType) line: 155    
    Verify.main(String[]) line: 88  
goneall commented 2 months ago

The simplest solution would be to just hold write locks instead of readlocks, but that would negatively impact concurrency.