Repository navigation
Description
Summary
WALFile holds a raw FileChannel. If the thread performing a commit is interrupted while inside channel.write(), NIO closes the channel and throws ClosedByInterruptException (AbstractInterruptibleChannel.begin() fires the interruptor even when the flag is already set, so no timing race is needed). The WALFile instance stays in activeWALFilePool[i] with open == true and a dead channel.
Nothing ever repairs or replaces that slot:
WALFilehas no reopen-after-ClosedChannelExceptionrecovery.PaginatedComponentFilegrew exactly that recovery for the data files in [storage] ClosedChannelException recovery in PaginatedComponentFile resurrects intentionally closed/dropped files #4930, including theThread.interrupted()clear/restore dance that a reopened channel needs. The WAL file, which is the one file whose loss costs committed data, was left without it.TransactionManager.checkWALFiles()catchesClosedChannelExceptionbeforeIOExceptionand does nothing butfile.close()- no log line, no fence, and it does not swap in a fresh WAL file or move the dead one toinactiveWALFilePool. TheIOExceptionbranch immediately below it does the opposite: it callslocalDatabase.fenceForRecovery(...)with a full explanation, precisely because "a WAL file this instance still has open just became inaccessible" must not be swallowed.ClosedChannelExceptionis anIOException, so the narrower catch silently steals the case the wider one was written to fence.- Once
close()has setopen = false,checkWALFiles()'s rotation branch (file != null && file.isOpen() && file.getSize() > MAX_LOG_FILE_SIZE) can never fire again for that slot, so the slot stays dead for the life of the database. writeTransactionToWALpicks its file bythreadId % activeWALFilePool.lengthand never falls back to another slot; it just spins forWRITE_WAL_TIMEOUT(30 s) and throwsTransactionException("Timeout on writing transaction to WAL").
Net effect: a single transient interrupt on one commit (a cancelled HTTP/gRPC request, a query timeout, a server shutting a request thread down, an async-executor cancellation) permanently removes 1/N of the WAL pool. Every thread that hashes to that slot afterwards pays a 30-second stall and then fails, with an error message that points at a slow disk rather than at the real cause. db.isOpen() still returns true and nothing is logged above FINE, so the database looks healthy. With the documented-and-legal arcadedb.txWalFiles=1 the database stops committing entirely.
Where (HEAD 417314c)
engine/src/main/java/com/arcadedb/engine/TransactionManager.java:1249
} catch (final ClosedChannelException e) {
try {
file.close();
} catch (IOException ex) {
// IGNORE IT
}
} catch (final IOException e) {
// #7479: a WAL file this instance still has open just became inaccessible. [...]
if (database.getEmbedded() instanceof LocalDatabase localDatabase) {
localDatabase.fenceForRecovery(...);
return;
}engine/src/main/java/com/arcadedb/engine/TransactionManager.java:350 (no fallback slot, no repair):
while (true) {
final WALFile file = activeWALFilePool[(int) (Thread.currentThread().threadId() % activeWALFilePool.length)];
if (file != null && file.acquire(() -> { ... }))
break;
if (System.currentTimeMillis() - begin > WRITE_WAL_TIMEOUT)
throw new TransactionException("Timeout on writing transaction to WAL");engine/src/main/java/com/arcadedb/engine/WALFile.java:563 - the append that dies, with no reopen path:
protected void append(final ByteBuffer buffer) throws IOException {
buffer.rewind();
long writePos = channel.size();
while (buffer.hasRemaining())
writePos += channel.write(buffer, writePos);
}Contrast engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java:108 (reopenChannelUnderWriteLock, #4930) which is the recovery the WAL file is missing.
Repro
WalSlotRepro.java - an embedded database, arcadedb.txWalFiles=1, one commit issued from a thread whose interrupt flag is set, then ordinary commits from clean threads, with one checkWALFilesForTesting() pass in between to stand in for the once-a-second housekeeping timer.
javac -cp "$(cat cp.txt):.../engine/target/classes" -d walslot/out walslot/com/arcadedb/engine/WalSlotRepro.java
java -cp "walslot/out:$(cat cp.txt):.../engine/target/classes" com.arcadedb.engine.WalSlotRepro
Actual output:
commit1-clean: OK
commit1-clean: took 5 ms
commit2-interrupted: com.arcadedb.exception.TransactionException: Transaction error on commit
caused by com.arcadedb.engine.WALException: Error on writing to WAL file .../walslotdb/txlog_0.wal
caused by java.nio.channels.ClosedByInterruptException: null
commit3-after-interrupt: com.arcadedb.exception.TransactionException: Transaction error on commit
commit3-after-interrupt: took 3 ms
--- running one WAL housekeeping pass (what the 1s timer does) ---
commit4-after-housekeeping: com.arcadedb.exception.TransactionException: Timeout on writing transaction to WAL
commit4-after-housekeeping: took 30010 ms
commit5-after-housekeeping: com.arcadedb.exception.TransactionException: Timeout on writing transaction to WAL
commit5-after-housekeeping: took 30016 ms
database open? true
commit3 is on a clean, never-interrupted thread and still fails - the damage is to the shared pool slot, not to the interrupted thread. commit4 and commit5 are the permanent state: 30 seconds of stall per transaction, forever, on an "open" database.
Suggested fix
Three independent, each individually sufficient, and worth doing together:
- Give
WALFilethe [storage] ClosedChannelException recovery in PaginatedComponentFile resurrects intentionally closed/dropped files #4930 treatment: onClosedChannelExceptioninsideappend()/getSize()/force(), and only whenopen == trueand the path still exists, clear the interrupt flag, reopen the channel (re-acquiring the advisory lock), retry once, restore the interrupt flag. The WAL content on disk is intact - only the descriptor died. - Failing that, make
checkWALFiles()replace the dead slot instead of merely closing it: retire the file intoinactiveWALFilePooland open a freshtxlog_<n>.walin its place, the same way the size-based rotation branch a few lines above already does. Today the slot is closed and abandoned. - At minimum, stop the narrower catch from swallowing the case the
IOExceptionbranch was written for: either delete theClosedChannelExceptioncatch (letting it fence, which is the GraphImporter fails to load data properly when ArcadeDB server is alive #7479 contract) or log and fence there too. Silently closing the only WAL file of a database and returning is the worst of the three outcomes.
Separately, writeTransactionToWAL should not spin 30 s against a slot it has already observed to be closed - !file.isOpen() is a permanent condition, not a transient one - and the resulting message should not read as a disk-latency problem.
Scope / confidence
Refutation attempts that failed:
- "
executeInReadLock/executeInWriteLockcatchClosedChannelExceptionand close the database, so this is handled." No:WALFile.acquire()wraps theClosedByInterruptExceptionin aWALException, which is aRuntimeException, so it is rethrown by thecatch (final RuntimeException e)arm before theClosedChannelExceptionarm can see it. Confirmed by the repro - the database is still open at the end. - "The housekeeping timer will rotate the file away." It cannot: the rotation branch requires
file.isOpen(), and theClosedChannelExceptionhandler has just setopen = false. Confirmed by the repro - two later housekeeping-equivalent states leave the slot dead. - "With the default pool size (cores) only one thread is affected."
writeTransactionToWALindexes bythreadId % lengthand has no fallback, so every thread congruent to that slot is affected, permanently; andtxWalFiles=1is a documented, supported value (it is the value GlobalConfiguration sweep: txWalFiles=0 breaks every commit though documented, bucketReuseSpaceMode is DATABASE-scoped but read globally, and four settings are unreachable or unread #7121 was about being unable to express), under which the whole database stops committing. - "An interrupt during commit is not realistic." The repro uses the ordinary, fully supported path: the interrupt flag is set before the commit, and
AbstractInterruptibleChannel.begin()closes the channel on the spot. Query timeouts, request cancellation and executor shutdown all set that flag.
What would falsify it: a caller above TransactionManager that detects the dead slot and rebuilds the pool. I grepped for every reference to activeWALFilePool and to createWALFilePool(); the pool is (re)built only in the constructor and in checkIntegrity(), i.e. only at open time.
Activity
fix(#7768): a WAL file reopens the channel a thread interrupt closed,…
robfrank commentedon Sep 22, 2026
Fixed in #8148. Taking your four points in order:
WALFilehad no reopen-after-ClosedChannelExceptionrecovery - fixed. It now gets the same channel-reopen treatmentPaginatedComponentFilehas carried since [storage] ClosedChannelException recovery in PaginatedComponentFile resurrects intentionally closed/dropped files #4930, applied to every channel operation in the class rather than just the commit path:append,force,getSizeand all three positional reads (funnelled through a newreadChunk). A reopen is refused only for a file closed on purpose or gone from disk.checkWALFiles()should replace the dead slot, not merely close it - argued rather than implemented, and the reasoning is in the PR: with (1) in place a slot can only go dead when the reopen is legitimately refused, and (3) then fences the database, so there is no live pool left to rotate a fresh file into.ClosedChannelExceptioncatch stole the case theIOExceptionbranch was written to fence - fixed. The catch is gone, so the case GraphImporter fails to load data properly when ArcadeDB server is alive #7479 wrote that fence for now fences; a shutdown racing the housekeeping pass stays benign.writeTransactionToWALoffers the transaction to the other files in the pool before spinning, and the timeout message names the per-slot pool state instead of implying disk latency.Two subtleties were worth the care:
append's retry restarts from the offset recorded before the first attempt, so an interrupted partial write is overwritten rather than left as a torn prefix, andreadChunkrewinds the buffer the same way on the read side. New regression testIssue7768InterruptedWalSlotTesthas 11 tests, one per covered entry point plus two negative guards, all proven to fail against the unfixed sources.Still open
SEVEREline per channel operation, so an interrupted recovery scan emits an unbounded flood - tracked as WALFile's interrupt reopen logs one SEVERE line per channel operation, so an interrupted recovery scan emits an unbounded flood #8139. Left out deliberately: quieting it is a visibility decision, and this issue is partly a report that the failure used to be invisible.WALFileGetTransactionTest.ioErrorOnChannelThrowsWALExceptioninduced its error by closing the channel, which is now a recoverable condition, so it would have passed for the wrong reason. Its assertion is untouched; only the inducement changed (the file is deleted too, making the reopen genuinely refuse).❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.