{"record":{"id":"bd27233f19d11aae","repo":"alibaba/nacos","slug":"watchfilecenter-already-shutdown","errorCode":null,"errorMessage":"WatchFileCenter already shutdown","messagePattern":"WatchFileCenter already shutdown","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sys/src/main/java/com/alibaba/nacos/sys/file/WatchFileCenter.java","lineNumber":282,"sourceCode":"            }\n        }\n        \n        private void eventOverflow() {\n            File dir = Paths.get(paths).toFile();\n            for (File file : Objects.requireNonNull(dir.listFiles())) {\n                // Subdirectories do not participate in listening\n                if (file.isDirectory()) {\n                    continue;\n                }\n                eventProcess(file.getName());\n            }\n        }\n        \n    }\n    \n    private static void checkState() {\n        if (CLOSED.get()) {\n            throw new IllegalStateException(\"WatchFileCenter already shutdown\");\n        }\n    }\n}\n","sourceCodeStart":264,"sourceCodeEnd":286,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/sys/src/main/java/com/alibaba/nacos/sys/file/WatchFileCenter.java#L264-L286","documentation":"Thrown by WatchFileCenter.checkState() when an operation (e.g. registering a new watcher) is attempted after the WatchFileCenter has been shut down (CLOSED flag is true). The center refuses post-shutdown work.","triggerScenarios":"After WatchFileCenter.shutdown() (or JVM shutdown hook) runs and sets CLOSED, a subsequent registerWatcher()/watch request invokes checkState() and fails.","commonSituations":"A component initializes lazily during Spring context closing and tries to register a file watcher after WatchFileCenter already shut down; a restart/reload flow re-registers watchers without checking liveness; ordering issue between shutdown hooks.","solutions":["Check WatchFileCenter is still active (or guard with isClosed) before registering watchers during shutdown.","Fix component lifecycle ordering so watchers register before shutdown.","Avoid lazy watcher registration in @PreDestroy or shutdown paths.","If re-registration is expected after a restart, ensure the center is re-initialized first."],"exampleFix":"// before (lazy register during shutdown)\n@PreDestroy\npublic void reload() {\n    WatchFileCenter.registerWatcher(path, watcher); // center already closed\n}\n\n// after (register in init, not destroy)\n@PostConstruct\npublic void init() {\n    if (!WatchFileCenter.isClosed()) {\n        WatchFileCenter.registerWatcher(path, watcher);\n    }\n}","handlingStrategy":"validation","validationCode":"if (WatchFileCenter.isClosed()) {\n    // skip registration; component is shutting down\n    return;\n}\nWatchFileCenter.registerWatcher(path, watcher);","typeGuard":null,"tryCatchPattern":"try {\n    WatchFileCenter.registerWatcher(path, watcher);\n} catch (IllegalStateException e) {\n    if (\"WatchFileCenter already shutdown\".equals(e.getMessage())) {\n        // skip; lifecycle ordering issue, do not retry\n    }\n    throw e;\n}","preventionTips":["Register watchers in @PostConstruct, never in @PreDestroy.","Guard post-shutdown registration with isClosed().","Order component startup/shutdown so watchers register before the center closes."],"tags":["sys","file-watch","lifecycle","shutdown"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}