alibaba/nacos · error · IllegalStateException
Publisher does not start
Error message
Publisher does not start
What it means
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.
Source
Thrown at common/src/main/java/com/alibaba/nacos/common/notify/DefaultPublisher.java:154
}
@Override
public boolean publish(Event event) {
checkIsStart();
boolean success = this.queue.offer(event);
if (!success) {
LOGGER.warn(
"Unable to plug in due to interruption, synchronize sending time, event : {}",
event);
receiveEvent(event);
return true;
}
return true;
}
void checkIsStart() {
if (!initialized) {
throw new IllegalStateException("Publisher does not start");
}
}
@Override
public void shutdown() {
this.shutdown = true;
this.queue.clear();
// Interrupt the thread to stop processing events: queue.take().
this.interrupt();
}
public boolean isInitialized() {
return initialized;
}
/**
* Receive and notifySubscriber to process the event.
*View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before DefaultPublisher pub = new DefaultPublisher(name, listener); pub.publish(event); // IllegalStateException: not started // after DefaultPublisher pub = new DefaultPublisher(name, listener); pub.start(); pub.publish(event);
Defensive patterns
Strategy: validation
Validate before calling
if (!publisher.isInitialized()) {
publisher.start();
}
publisher.publish(event); Type guard
boolean isPublisherReady(DefaultPublisher p) {
return p != null && p.isInitialized();
} Try / catch
try {
publisher.publish(event);
} catch (IllegalStateException e) {
log.error("Publisher {} not started", publisher.getName(), e);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The subscriber has no event publisher
- PARAMETER_MISSING
- RESOURCE_CONFLICT
- 20005
- NacosLockService has been shut down
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/e45f1b6631ba568e.
Report an issue: GitHub.