{"record":{"id":"bf1b03c5135a962f","repo":"alibaba/nacos","slug":"401","errorCode":"-401","errorMessage":"Interrupted while shutting down service info disk cache refresher","messagePattern":"Interrupted while shutting down service info disk cache refresher","errorType":"exception","errorClass":"NacosException","httpStatus":null,"severity":"warning","filePath":"client/src/main/java/com/alibaba/nacos/client/naming/cache/ServiceInfoDiskCacheRefresher.java","lineNumber":153,"sourceCode":"    \n    /**\n     * Shutdown refresher after flushing pending events.\n     *\n     * @throws NacosException if interrupted during shutdown\n     */\n    @Override\n    public void shutdown() throws NacosException {\n        flushPendingEvents();\n        refreshExecutor.shutdown();\n        try {\n            if (!refreshExecutor.awaitTermination(shutdownTimeoutMilliseconds,\n                TimeUnit.MILLISECONDS)) {\n                NAMING_LOGGER.warn(\"[NA] timeout while waiting service info disk cache refresher \"\n                    + \"to shutdown, pending event size: {}\", pendingEvents.size());\n            }\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new NacosException(NacosException.CLIENT_DISCONNECT,\n                \"Interrupted while shutting down service info disk cache refresher\", e);\n        }\n        flushPendingEvents();\n    }\n    \n    @FunctionalInterface\n    interface DiskCacheWriter {\n        \n        /**\n         * Write service info to disk cache.\n         *\n         * @param serviceInfo service info\n         * @param cacheDir cache dir\n         * @return {@code true} if write success, otherwise {@code false}\n         */\n        boolean write(ServiceInfo serviceInfo, String cacheDir);\n    }\n}","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/naming/cache/ServiceInfoDiskCacheRefresher.java#L135-L171","documentation":"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.","triggerScenarios":"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.","commonSituations":"Application/container shutdown hooks firing interrupts; forced thread interruption during graceful shutdown; servlet/context destroy racing with the naming client shutdown.","solutions":["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.","Avoid interrupting the thread performing shutdown; let awaitTermination complete within shutdownTimeoutMilliseconds.","Tune shutdownTimeoutMilliseconds if the refresher legitimately needs more time to flush."],"exampleFix":"// before\nrefresher.shutdown(); // may throw on interrupt during teardown\n\n// after\ntry {\n    refresher.shutdown();\n} catch (NacosException e) {\n    LOGGER.warn(\"Disk cache refresher shutdown interrupted (code {})\", e.getErrCode());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { refresher.shutdown(); } catch (NacosException e) { LOGGER.warn(\"Disk cache refresher shutdown interrupted (code {})\", e.getErrCode()); }","preventionTips":["Do not interrupt the thread performing shutdown; let awaitTermination finish.","Tune shutdownTimeoutMilliseconds if flush needs more time.","Run client shutdown in a non-interrupted context (e.g. a dedicated shutdown hook)."],"tags":["naming","disk-cache","shutdown","interrupted","lifecycle"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}