Repository navigation
Closed
Milestone
Description
CiphertextDirCache uses an async cache to load/handle ciphertext dirs:
CiphertextDirectory get(CryptoPath cleartextPath, CipherDirLoader ifAbsent) throws IOException {
var futureMapping = new CompletableFuture<CiphertextDirectory>();
var currentMapping = ciphertextDirectories.asMap().putIfAbsent(cleartextPath, futureMapping);
if (currentMapping != null) {
return currentMapping.join();
} else {
futureMapping.complete(ifAbsent.load());
return futureMapping.join();
}
}By contract, ifAbsent.load() is allowed to throw IOExceptions. But if such an exception is thrown,
futureMapping is already in the cache and is never completed (normal or exceptionally) and hence, never removed; there is no try/finally.
Every later caller for the same cleartext path takes the branch at line 64
and blocks in CompletableFuture.join(), waiting for a completion that can
no longer happen, and join() does not honour interrupts.
In summary:
- The cache entry never gets cleaned up (src/main/java/org/cryptomator/cryptofs/CiphertextDirCache.java:61-70). get() puts an empty CompletableFuture into the cache and only completes it when loading succeeds. If ifAbsent.load() throws, that future stays in the cache and never finishes. Every later get() for the same path calls currentMapping.join() and waits forever, and interrupting the thread doesn't stop it. No concurrency is needed to trigger this.
- Expiry doesn't clear it. Caffeine's async cache doesn't evict or expire futures that haven't completed yet, so the 20 s / 5000-entry limits don't help.
- To trigger it: (DirectoryIdLoader.java:36-41). A 0-byte dir.c9r, it throws before any decryption happens.
- It spreads to the whole vault (dir/DirectoryStreamFactory.java:38-42). newDirectoryStream is synchronized and resolves the directory while holding the lock. A second listing of the broken path blocks while holding that lock. After that, every other directory listing and close() (also synchronized) waits behind it. Because close() hangs, the rest of CryptoFileSystemImpl.close never runs, including cryptor::destroy.
Privately reported by @assakafpix
Activity