Skip to content

One interrupted commit permanently kills a WAL pool slot: every later transaction on that slot blocks 30 s and fails with "Timeout on writing transaction to WAL" #7768

Closed

Description

@ruispereira

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:

  • WALFile has no reopen-after-ClosedChannelException recovery. PaginatedComponentFile grew exactly that recovery for the data files in [storage] ClosedChannelException recovery in PaginatedComponentFile resurrects intentionally closed/dropped files #4930, including the Thread.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() catches ClosedChannelException before IOException and does nothing but file.close() - no log line, no fence, and it does not swap in a fresh WAL file or move the dead one to inactiveWALFilePool. The IOException branch immediately below it does the opposite: it calls localDatabase.fenceForRecovery(...) with a full explanation, precisely because "a WAL file this instance still has open just became inaccessible" must not be swallowed. ClosedChannelException is an IOException, so the narrower catch silently steals the case the wider one was written to fence.
  • Once close() has set open = 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.
  • writeTransactionToWAL picks its file by threadId % activeWALFilePool.length and never falls back to another slot; it just spins for WRITE_WAL_TIMEOUT (30 s) and throws TransactionException("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:

  1. Give WALFile the [storage] ClosedChannelException recovery in PaginatedComponentFile resurrects intentionally closed/dropped files #4930 treatment: on ClosedChannelException inside append()/getSize()/force(), and only when open == true and 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.
  2. Failing that, make checkWALFiles() replace the dead slot instead of merely closing it: retire the file into inactiveWALFilePool and open a fresh txlog_<n>.wal in its place, the same way the size-based rotation branch a few lines above already does. Today the slot is closed and abandoned.
  3. At minimum, stop the narrower catch from swallowing the case the IOException branch was written for: either delete the ClosedChannelException catch (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/executeInWriteLock catch ClosedChannelException and close the database, so this is handled." No: WALFile.acquire() wraps the ClosedByInterruptException in a WALException, which is a RuntimeException, so it is rethrown by the catch (final RuntimeException e) arm before the ClosedChannelException arm 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 the ClosedChannelException handler has just set open = 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." writeTransactionToWAL indexes by threadId % length and has no fallback, so every thread congruent to that slot is affected, permanently; and txWalFiles=1 is 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

  1. added this to the 26.10.1 milestone on Sep 17, 2026
  2. added
    severity:critical
    on Sep 19, 2026
  3. self-assigned this
    on Sep 21, 2026
  4. added
    in progress
    engine
    concurrency
    on Sep 22, 2026
  5. added a commit that references this issue on Sep 22, 2026
  6. robfrank commented on Sep 22, 2026

    @robfrank
    Collaborator

    Fixed in #8148. Taking your four points in order:

    1. WALFile had no reopen-after-ClosedChannelException recovery - fixed. It now gets the same channel-reopen treatment PaginatedComponentFile has 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, getSize and all three positional reads (funnelled through a new readChunk). A reopen is refused only for a file closed on purpose or gone from disk.
    2. 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.
    3. The narrow ClosedChannelException catch stole the case the IOException branch 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.
    4. The 30 s spin and the misleading message - fixed. writeTransactionToWAL offers 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, and readChunk rewinds the buffer the same way on the read side. New regression test Issue7768InterruptedWalSlotTest has 11 tests, one per covered entry point plus two negative guards, all proven to fail against the unfixed sources.

    Still open

    • The reopen logs one SEVERE line 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.
    • One existing test changed by design: WALFileGetTransactionTest.ioErrorOnChannelThrowsWALException induced 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.

  7. removed
    in progress
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyengineseverity:critical

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions