greenrobot/greenDAO · error · DaoException

Interrupted while waiting for all operations to complete

Error message

Interrupted while waiting for all operations to complete

What it means

AsyncOperationExecutor.waitForCompletion() blocks until all enqueued operations have finished (the executor's count reaches the expected total). If the calling thread is interrupted while waiting on the executor monitor, the InterruptedException is converted into this DaoException.

Solutions

  1. Don't interrupt the waiting thread; drain async ops before shutdown, or call waitForCompletion earlier in lifecycle.
  2. Catch DaoException and restore the interrupt flag (Thread.currentThread().interrupt()).
  3. Use waitForCompletion(int maxMillis) if you want a bounded wait that returns false on timeout instead of blocking forever.
  4. Prefer listener callbacks (AsyncOperationListener.onOperationCompleted) to avoid blocking the main/work thread.

Example fix

// before
asyncSession.waitForCompletion(); // throws DaoException when interrupted
// after
try {
    asyncSession.waitForCompletion();
} catch (DaoException e) {
    Thread.currentThread().interrupt();
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    asyncSession.waitForCompletion();
} catch (DaoException e) {
    Thread.currentThread().interrupt();
    // abort batch or persist progress, then return
}

Prevention

When it happens

Trigger: Calling asyncSession.waitForCompletion() (executor-level, waits for ALL pending async ops) from a thread that is interrupted — e.g. during ExecutorService shutdownNow, Activity destruction with thread cancellation, or explicit interrupt().

Common situations: App teardown or test frameworks interrupting threads that were waiting for a batch of async DAO writes to drain before proceeding.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08). Data as JSON: /api/errors/f8caa9e8b17bd4f1. Report an issue: GitHub.

Appendix: source

Thrown at DaoCore/src/main/java/org/greenrobot/greendao/async/AsyncOperationExecutor.java:114

    public void setListenerMainThread(AsyncOperationListener listenerMainThread) {
        this.listenerMainThread = listenerMainThread;
    }

    public synchronized boolean isCompleted() {
        return countOperationsEnqueued == countOperationsCompleted;
    }

    /**
     * Waits until all enqueued operations are complete. If the thread gets interrupted, any
     * {@link InterruptedException} will be rethrown as a {@link DaoException}.
     */
    public synchronized void waitForCompletion() {
        while (!isCompleted()) {
            try {
                wait();
            } catch (InterruptedException e) {
                throw new DaoException("Interrupted while waiting for all operations to complete", e);
            }
        }
    }

    /**
     * Waits until all enqueued operations are complete, but at most the given amount of milliseconds. If the thread
     * gets interrupted, any {@link InterruptedException} will be rethrown as a {@link DaoException}.
     *
     * @return true if operations completed in the given time frame.
     */
    public synchronized boolean waitForCompletion(int maxMillis) {
        if (!isCompleted()) {
            try {
                wait(maxMillis);
            } catch (InterruptedException e) {
                throw new DaoException("Interrupted while waiting for all operations to complete", e);
            }
        }

View on GitHub (pinned to 0bbb338e17)