apache/shenyu · error · RejectedExecutionException

The task queue does not have executor!

Error message

The task queue does not have executor!

What it means

TaskQueue.offer() requires a reference to its owning EagerExecutorService, set via setExecutor(). If getExecutor() is null (queue used before being wired to an executor, or executor reference cleared), the offer cannot route the task and throws RejectedExecutionException('The task queue does not have executor!').

Solutions

  1. Always create the queue via EagerExecutorService (which calls setExecutor) instead of constructing TaskQueue standalone.
  2. Ensure setExecutor() is invoked before any offer/retryOffer use.
  3. Check for a race where producers start before executor initialization completes.
  4. In tests, inject a mock/stub EagerExecutorService into the queue before offering.

Example fix

// before
TaskQueue<Runnable> queue = new TaskQueue<>();
queue.offer(task); // no executor wired
// after
EagerExecutorService exec = new EagerExecutorService(core, max, keepAlive, unit, queue, "shenyu", new EagerPolicy<>());
// executor wires itself into the queue; offer through exec.execute(task)
Defensive patterns

Strategy: validation

Validate before calling

if (queue.getExecutor() == null) {
    throw new IllegalStateException("TaskQueue must be wired to an EagerExecutorService before use");
}

Try / catch

try {
    queue.offer(task);
} catch (RejectedExecutionException e) {
    LOG.error("Queue not initialized: {}", e.getMessage());
}

Prevention

When it happens

Trigger: Offering into a TaskQueue that was constructed manually or deserialized without calling setExecutor(); submitting tasks before the EagerExecutorService finished wiring the queue.

Common situations: Creating TaskQueue directly and passing it to a plain ThreadPoolExecutor that never calls setExecutor; tests constructing the queue standalone; initialization-order bugs where produce happens before executor setup.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/abc73e9b7bbc02e5. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/TaskQueue.java:47

    /**
     * get executor.
     *
     * @return the executor
     */
    EagerExecutorService getExecutor();

    /**
     * set the executor.
     *
     * @param executor executor
     */
    void setExecutor(EagerExecutorService executor);

    @Override
    default boolean offer(final E e) {
        if (Objects.isNull(getExecutor())) {
            throw new RejectedExecutionException("The task queue does not have executor!");
        }

        int currentPoolThreadSize = getExecutor().getPoolSize();
        // have free worker. put task into queue to let the worker deal with task.
        if (getExecutor().getActiveCount() < currentPoolThreadSize) {
            return doOffer(e);
        }

        // return false to let executor create new worker.
        if (currentPoolThreadSize < getExecutor().getMaximumPoolSize()) {
            return false;
        }

        // currentPoolThreadSize >= max
        return doOffer(e);
    }

    /**

View on GitHub (pinned to 567142e072)