{"record":{"id":"e45f1b6631ba568e","repo":"alibaba/nacos","slug":"publisher-does-not-start","errorCode":null,"errorMessage":"Publisher does not start","messagePattern":"Publisher does not start","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/notify/DefaultPublisher.java","lineNumber":154,"sourceCode":"    }\n    \n    @Override\n    public boolean publish(Event event) {\n        checkIsStart();\n        boolean success = this.queue.offer(event);\n        if (!success) {\n            LOGGER.warn(\n                \"Unable to plug in due to interruption, synchronize sending time, event : {}\",\n                event);\n            receiveEvent(event);\n            return true;\n        }\n        return true;\n    }\n    \n    void checkIsStart() {\n        if (!initialized) {\n            throw new IllegalStateException(\"Publisher does not start\");\n        }\n    }\n    \n    @Override\n    public void shutdown() {\n        this.shutdown = true;\n        this.queue.clear();\n        // Interrupt the thread to stop processing events: queue.take().\n        this.interrupt();\n    }\n    \n    public boolean isInitialized() {\n        return initialized;\n    }\n    \n    /**\n     * Receive and notifySubscriber to process the event.\n     *","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/notify/DefaultPublisher.java#L136-L172","documentation":"Thrown by DefaultPublisher.checkIsStart() when the publisher's initialized flag is still false — i.e. start() was never called, or the object was constructed but not started before an event was published. It is an IllegalStateException (not a runtime Nacos exception) signalling the event-dispatch thread is not alive.","triggerScenarios":"Calling publisher.publish(event) or any path that calls checkIsStart() on a DefaultPublisher that was constructed via new DefaultPublisher(...) but whose start() was never invoked; using a publisher after shutdown() reset its thread state; accessing a publisher from NotifyCenter before its lazy init completed.","commonSituations":"Custom Event/Subscriber wiring that creates a DefaultPublisher directly instead of going through NotifyCenter; a race where shutdown() runs concurrently; a unit test that instantiates a publisher and immediately publishes without start(); the NotifyCenter publisher pool not yet initialized at boot.","solutions":["Ensure publisher.start() is called (and returns) before any publish; in normal usage, rely on NotifyCenter which manages publisher lifecycle.","Do not construct DefaultPublisher directly — register subscribers through NotifyCenter.addSubscriber so the framework starts the publisher.","In tests, call publisher.start() in @Before and publish only after the thread is alive; check publisher.isInitialized() if unsure.","Avoid publishing after shutdown(); guard with a lifecycle check or recreate the publisher."],"exampleFix":"// before\nDefaultPublisher pub = new DefaultPublisher(name, listener);\npub.publish(event); // IllegalStateException: not started\n\n// after\nDefaultPublisher pub = new DefaultPublisher(name, listener);\npub.start();\npub.publish(event);","handlingStrategy":"validation","validationCode":"if (!publisher.isInitialized()) {\n    publisher.start();\n}\npublisher.publish(event);","typeGuard":"boolean isPublisherReady(DefaultPublisher p) {\n    return p != null && p.isInitialized();\n}","tryCatchPattern":"try {\n    publisher.publish(event);\n} catch (IllegalStateException e) {\n    log.error(\"Publisher {} not started\", publisher.getName(), e);\n    throw e;\n}","preventionTips":["Use NotifyCenter.addSubscriber rather than constructing DefaultPublisher directly so lifecycle is managed for you.","In tests, start publishers in @Before and assert isInitialized() before publishing.","Never publish after shutdown(); recreate the publisher if needed."],"tags":["event-bus","notify-center","lifecycle","state"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}