karatelabs/karate · warning

registered while , stopping immediately

Error message

registered while {}, stopping immediately: {}

What it means

`KarateLifecycle.register` normally buffers stoppables for shutdown, but if registration happens while the lifecycle is already stopping or shut down, the component is stopped immediately with the remaining budget and this warning is logged. This prevents registering a resource that would otherwise never be stopped.

Solutions

  1. Ensure all resource creation completes before shutdown begins (join async tasks first)
  2. Do not start new stoppable resources during teardown; guard creation with a lifecycle check
  3. If intentional, accept the warning — the component was still stopped with the remaining budget
  4. Serialize setup/teardown to avoid concurrent shutdown and registration

Example fix

// before
executor.submit(() -> startServerAndRegister()); // may run during shutdownAll()
// after
executor.submit(() -> startServerAndRegister()).get(); // complete before teardown begins
Defensive patterns

Strategy: type-guard

Validate before calling

if (lifecycle.isShuttingDown()) throw new IllegalStateException("refusing to register " + name + " during shutdown");

Type guard

boolean safeToRegister = lifecycle.phase() != Phase.SHUTTING_DOWN && lifecycle.phase() != Phase.SHUT_DOWN;

Prevention

When it happens

Trigger: A server/client/connection is created (and registers itself) concurrently with, or after, `shutdownAll()` — e.g. a late `karate.start()` during teardown, async task creating a stoppable while tests are shutting down; re-registration after a prior shutdown.

Common situations: Race between test teardown and background/async resource creation; shutdown triggered by a timeout or failure while a scenario still starts new resources; double shutdown in nested suites.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/dafe817511b1d439. Report an issue: GitHub.

Appendix: source

Thrown at karate-js/src/main/java/io/karatelabs/common/KarateLifecycle.java:178

        }
        Phase current;
        long budgetNanos;
        synchronized (LOCK) {
            current = phase;
            if (current == Phase.RUNNING) {
                synchronized (REGISTERED) {
                    if (indexOf(stoppable) < 0) {
                        REGISTERED.add(stoppable);
                    }
                }
                return;
            }
            budgetNanos = current == Phase.SHUTTING_DOWN
                    ? Math.max(deadlineNanos - System.nanoTime(), 0)
                    : DEFAULT_TIMEOUT.toNanos();
        }
        // outside the lock: stopping can block, and the drain needs the lock to record results
        logger.warn("registered while {}, stopping immediately: {}", current, name(stoppable));
        stopBounded(stoppable, budgetNanos);
    }

    /**
     * Remove a component from the register — call from the component's own stop path, so that
     * something which stopped by itself (peer closed the socket, process exited) drops off too.
     * Removing something not registered is a no-op, and null is ignored.
     */
    public static void unregister(Stoppable stoppable) {
        if (stoppable == null) {
            return;
        }
        synchronized (REGISTERED) {
            int index = indexOf(stoppable);
            if (index >= 0) {
                REGISTERED.remove(index);
            }
        }

View on GitHub (pinned to a22eb90246)