alibaba/nacos · warning · NacosException

-401

-401

Error message

Interrupted while shutting down service info disk cache refresher

What it means

Thrown by ServiceInfoDiskCacheRefresher.shutdown() when the thread is interrupted while awaiting termination of the refresh executor. The shutdown() flushes pending events, calls refreshExecutor.shutdown(), then awaitTermination; an InterruptedException during that wait re-interrupts the current thread and throws NacosException with code CLIENT_DISCONNECT (-401). This is a lifecycle/shutdown interruption, not a data error.

Source

Thrown at client/src/main/java/com/alibaba/nacos/client/naming/cache/ServiceInfoDiskCacheRefresher.java:153

    
    /**
     * Shutdown refresher after flushing pending events.
     *
     * @throws NacosException if interrupted during shutdown
     */
    @Override
    public void shutdown() throws NacosException {
        flushPendingEvents();
        refreshExecutor.shutdown();
        try {
            if (!refreshExecutor.awaitTermination(shutdownTimeoutMilliseconds,
                TimeUnit.MILLISECONDS)) {
                NAMING_LOGGER.warn("[NA] timeout while waiting service info disk cache refresher "
                    + "to shutdown, pending event size: {}", pendingEvents.size());
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new NacosException(NacosException.CLIENT_DISCONNECT,
                "Interrupted while shutting down service info disk cache refresher", e);
        }
        flushPendingEvents();
    }
    
    @FunctionalInterface
    interface DiskCacheWriter {
        
        /**
         * Write service info to disk cache.
         *
         * @param serviceInfo service info
         * @param cacheDir cache dir
         * @return {@code true} if write success, otherwise {@code false}
         */
        boolean write(ServiceInfo serviceInfo, String cacheDir);
    }
}

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Catch NacosException around the refresher/client shutdown and log it; the interrupt status is already re-set by the code (Thread.currentThread().interrupt()), so propagation is intentional.
  2. Avoid interrupting the thread performing shutdown; let awaitTermination complete within shutdownTimeoutMilliseconds.
  3. Tune shutdownTimeoutMilliseconds if the refresher legitimately needs more time to flush.

Example fix

// before
refresher.shutdown(); // may throw on interrupt during teardown

// after
try {
    refresher.shutdown();
} catch (NacosException e) {
    LOGGER.warn("Disk cache refresher shutdown interrupted (code {})", e.getErrCode());
}
Defensive patterns

Strategy: try-catch

Try / catch

try { refresher.shutdown(); } catch (NacosException e) { LOGGER.warn("Disk cache refresher shutdown interrupted (code {})", e.getErrCode()); }

Prevention

When it happens

Trigger: The thread calling shutdown() on the disk-cache refresher is itself interrupted (e.g. by a JVM shutdown hook or container teardown) while awaitTermination is blocking; concurrent/interrupted shutdown sequences; a parent thread group interrupting all members during teardown.

Common situations: Application/container shutdown hooks firing interrupts; forced thread interruption during graceful shutdown; servlet/context destroy racing with the naming client shutdown.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/bf1b03c5135a962f. Report an issue: GitHub.