alibaba/nacos · error · NacosApiException

21008

21008

Error message

service %s not found!

What it means

Thrown by ServiceOperatorV2Impl.update when ServiceManager does NOT contain a singleton for the given Service. Error code 21008 maps to ErrorCode.SERVICE_NOT_EXIST with NacosException.INVALID_PARAM (400). Update requires the service to already exist — it modifies metadata on an existing singleton.

Source

Thrown at naming/src/main/java/com/alibaba/nacos/naming/core/ServiceOperatorV2Impl.java:108

     *
     * @param service  v2 service
     * @param metadata new metadata of service
     * @throws NacosException nacos exception during creating
     */
    public void create(Service service, ServiceMetadata metadata) throws NacosException {
        if (ServiceManager.getInstance().containSingleton(service)) {
            throw new NacosApiException(NacosException.INVALID_PARAM,
                ErrorCode.SERVICE_ALREADY_EXIST,
                String.format("specified service %s already exists!",
                    service.getGroupedServiceName()));
        }
        metadataOperateService.updateServiceMetadata(service, metadata);
    }
    
    @Override
    public void update(Service service, ServiceMetadata metadata) throws NacosException {
        if (!ServiceManager.getInstance().containSingleton(service)) {
            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SERVICE_NOT_EXIST,
                String.format("service %s not found!", service.getGroupedServiceName()));
        }
        metadataOperateService.updateServiceMetadata(service, metadata);
        NotifyCenter.publishEvent(new InfoChangeEvent.ServiceInfoChangeEvent(service));
    }
    
    @Override
    public void delete(String namespaceId, String serviceName) throws NacosException {
        Service service = getServiceFromGroupedServiceName(namespaceId, serviceName, true);
        delete(service);
    }
    
    /**
     * Delete service.
     *
     * @param service service v2
     * @throws NacosException nacos exception during delete
     */

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Create the service first via create() if it does not exist, then call update().
  2. Verify the namespaceId, groupName, and serviceName match the originally created service exactly.
  3. Check that empty-service cleanup has not removed the service (increase nacos.naming.empty.service.expired.time if needed).
  4. Query the service via queryService() before updating to confirm existence.

Example fix

// before
serviceOperatorV2.update(service, metadata);

// after — ensure existence first
if (!ServiceManager.getInstance().containSingleton(service)) {
    serviceOperatorV2.create(service, metadata);
} else {
    serviceOperatorV2.update(service, metadata);
}
Defensive patterns

Strategy: validation

Validate before calling

Service service = Service.newService(namespaceId, groupName, serviceName, ephemeral);
if (!ServiceManager.getInstance().containSingleton(service)) {
    serviceOperatorV2.create(service, metadata);
} else {
    serviceOperatorV2.update(service, metadata);
}

Try / catch

try {
    serviceOperatorV2.update(service, metadata);
} catch (NacosApiException e) {
    if (e.getErrCode() == NacosException.INVALID_PARAM
            && ErrorCode.SERVICE_NOT_EXIST.getCode() == 21008) {
        serviceOperatorV2.create(service, metadata);
    } else throw e;
}

Prevention

When it happens

Trigger: Calling the update-service metadata API for a (namespaceId, groupName, serviceName) that was never created or has already been deleted. Also triggered when the namespace or group name is mistyped so the service key does not resolve to an existing singleton.

Common situations: Attempting to update service metadata before the service was created. Service was deleted by another operator or by empty-service cleanup. Namespace/group name mismatch between the update call and the original create. Migrating services between environments and forgetting to create first.

Related errors


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