alibaba/nacos · warning · NacosApiException
21007
21007
Error message
specified service %s already exists!
What it means
Thrown by ServiceOperatorV2Impl.create when ServiceManager already contains a singleton for the given Service. Error code 21007 maps to ErrorCode.SERVICE_ALREADY_EXIST with NacosException.INVALID_PARAM (400). The service is keyed by (namespace, group, name), so any pre-existing service with that exact triple blocks creation.
Source
Thrown at naming/src/main/java/com/alibaba/nacos/naming/core/ServiceOperatorV2Impl.java:97
@Override
public void create(String namespaceId, String serviceName, ServiceMetadata metadata)
throws NacosException {
Service service =
getServiceFromGroupedServiceName(namespaceId, serviceName, metadata.isEphemeral());
create(service, metadata);
}
/**
* Create new service.
*
* @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));
}
@OverrideView on GitHub (pinned to 9b989acdf1)
Solutions
- Check ServiceManager.getInstance().containSingleton(service) or query the service API before calling create.
- Make provisioning scripts idempotent: treat SERVICE_ALREADY_EXIST (21007) as success.
- If the service is stale, delete it first (after unregistering all instances) then recreate.
- Use a guard: create-or-update semantics instead of bare create.
Example fix
// before
serviceOperatorV2.create(service, metadata);
// after — idempotent create
if (!ServiceManager.getInstance().containSingleton(service)) {
serviceOperatorV2.create(service, metadata);
} Defensive patterns
Strategy: validation
Validate before calling
Service service = Service.newService(namespaceId, groupName, serviceName, ephemeral);
if (ServiceManager.getInstance().containSingleton(service)) {
// already exists — skip create or treat as success
return;
}
serviceOperatorV2.create(service, metadata); Try / catch
try {
serviceOperatorV2.create(service, metadata);
} catch (NacosApiException e) {
if (e.getErrCode() == NacosException.INVALID_PARAM
&& ErrorCode.SERVICE_ALREADY_EXIST.getCode() == 21007) {
// idempotent: already created, continue
} else throw e;
} Prevention
- Make service-provisioning scripts idempotent by checking existence first.
- Treat SERVICE_ALREADY_EXIST as success in automation.
- Avoid concurrent create calls for the same service key.
When it happens
Trigger: Calling the create-service API (POST /v3/admin/ns/service or equivalent) for a (namespaceId, groupName, serviceName) triple that already has a registered singleton. Happens during automated provisioning scripts that create services idempotently without first checking existence, or during retry after a partial failure.
Common situations: Deployment automation re-running a create-service step. A previous create succeeded but the caller did not receive the response (network timeout) and retried. Two concurrent create requests for the same service. Service exists from a prior application lifecycle and was never cleaned up.
Related errors
- 10000
- 400
- Param 'serviceName' is illegal, serviceName is blank
- Param 'groupName' is illegal, groupName is blank
- Param 'serviceName' is illegal, it should be format as 'grou
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/529d691235310d48.
Report an issue: GitHub.