alibaba/nacos · error · NacosException

INVALID_PARAM

INVALID_PARAM

Error message

Unsupported request type %s

What it means

Thrown by BatchInstanceRequestHandler.handle() when a gRPC BatchInstanceRequest carries a request type that is not BATCH_REGISTER_INSTANCE. The handler switches on request.getType(); only batch-register is implemented, so any other type yields NacosException.INVALID_PARAM with the offending type in the message. Usually signals a client/server contract mismatch.

Source

Thrown at naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/BatchInstanceRequestHandler.java:73

    
    @Override
    @NamespaceValidation
    @TpsControl(pointName = "RemoteNamingInstanceBatchRegister",
        name = "RemoteNamingInstanceBatchRegister")
    @Secured(action = ActionTypes.WRITE)
    @ExtractorManager.Extractor(rpcExtractor = BatchInstanceRequestParamExtractor.class)
    public BatchInstanceResponse handle(BatchInstanceRequest request, RequestMeta meta)
        throws NacosException {
        Service service = Service.newService(request.getNamespace(), request.getGroupName(),
            request.getServiceName(),
            true);
        InstanceUtil.batchSetInstanceIdIfEmpty(request.getInstances(),
            service.getGroupedServiceName());
        switch (request.getType()) {
            case NamingRemoteConstants.BATCH_REGISTER_INSTANCE:
                return batchRegisterInstance(service, request, meta);
            default:
                throw new NacosException(NacosException.INVALID_PARAM,
                    String.format("Unsupported request type %s", request.getType()));
        }
    }
    
    private BatchInstanceResponse batchRegisterInstance(Service service,
        BatchInstanceRequest request,
        RequestMeta meta) {
        clientOperationService.batchRegisterInstance(service, request.getInstances(),
            meta.getConnectionId());
        publishBatchRegisterInstanceTraceEvent(service, request, meta);
        return new BatchInstanceResponse(NamingRemoteConstants.BATCH_REGISTER_INSTANCE);
    }
    
    private void publishBatchRegisterInstanceTraceEvent(Service service,
        BatchInstanceRequest request,
        RequestMeta meta) {
        long eventTime = System.currentTimeMillis();
        String clientIp = NamingRequestUtil.getSourceIpForGrpcRequest(meta);

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Ensure the BatchInstanceRequest type equals NamingRemoteConstants.BATCH_REGISTER_INSTANCE.
  2. Align client and server Nacos versions (same minor release).
  3. For single register/deregister, use InstanceRequest instead of BatchInstanceRequest.

Example fix

// before
BatchInstanceRequest req = new BatchInstanceRequest(ns, group, svc, "batchDeregister", instances);
// after
BatchInstanceRequest req = new BatchInstanceRequest(ns, group, svc,
    NamingRemoteConstants.BATCH_REGISTER_INSTANCE, instances);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!NamingRemoteConstants.BATCH_REGISTER_INSTANCE.equals(request.getType())) {
    throw new IllegalArgumentException(
        "BatchInstanceRequest type must be batchRegisterInstance, was: " + request.getType());
}

Type guard

static boolean isSupportedBatchType(String type) {
    return NamingRemoteConstants.BATCH_REGISTER_INSTANCE.equals(type);
}

Try / catch

try {
    client.batchRegisterInstance(service, instances);
} catch (NacosException e) {
    if (e.getErrCode() == NacosException.INVALID_PARAM
        && e.getMessage().contains("Unsupported request type")) {
        // align SDK version with server, then rebuild request with correct type
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Client sends a BatchInstanceRequest whose type is something other than 'batchRegisterInstance' (e.g. a deregister or an unknown custom string).

Common situations: Client SDK version newer or older than the server, sending a type the server does not recognize; custom/forked client setting an incorrect type constant; sending a BatchInstanceRequest for an operation that should use InstanceRequest.

Related errors


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