alibaba/nacos · error · NacosException
400
400
Error message
no server available
What it means
Thrown by AiHttpClientProxy.reqApiStringWithHeader() with code INVALID_PARAM (400) when the server list is empty. This variant is used by queryAgentSpec() which fetches AgentSpec JSON with response headers (X-Nacos-AgentSpec-Md5, X-Nacos-AgentSpec-Resolved-Version). No network request is attempted — pre-flight failure.
Source
Thrown at client/src/main/java/com/alibaba/nacos/client/ai/remote/AiHttpClientProxy.java:770
}
}
private String buildUrl(String serverAddr, String relativePath) {
if (!serverAddr.startsWith(HTTP_PREFIX) && !serverAddr.startsWith(HTTPS_PREFIX)) {
serverAddr = (ENABLE_HTTPS ? HTTPS_PREFIX : HTTP_PREFIX) + serverAddr;
}
String contextPath = serverListManager.getContextPath();
return serverAddr + ContextPathUtil.normalizeContextPath(contextPath) + relativePath;
}
/**
* Request API returning String body with headers exposed, propagating 304 immediately.
*/
private HttpRestResult<String> reqApiStringWithHeader(String api,
Map<String, String> params, RequestResource resource) throws NacosException {
List<String> servers = serverListManager.getServerList();
if (servers.isEmpty()) {
throw new NacosException(NacosException.INVALID_PARAM, "no server available");
}
NacosException exception = new NacosException();
int index = ThreadLocalRandom.current().nextInt(servers.size());
for (int i = 0; i < Math.max(servers.size(), MAX_RETRY); i++) {
String server = servers.get(index % servers.size());
try {
return callServerStringWithHeader(api, params, server, resource);
} catch (NacosException e) {
if (NacosException.NOT_MODIFIED == e.getErrCode()) {
throw e;
}
exception = e;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Request {} to server {} failed.", api, server, e);
}
}View on GitHub (pinned to 9b989acdf1)
Solutions
- Set serverAddr in properties before creating the AI service.
- Verify at least one Nacos server node is reachable.
- Check ServerListManager logs for server-list population failures.
Example fix
// before
Properties props = new Properties();
props.setProperty("namespace", "dev");
// forgot serverAddr
NacosAiFactory.createAiService(props).queryAgentSpec("spec", null, null, null);
// after
props.setProperty(PropertyKeyConst.SERVER_ADDR, "nacos.example.com:8848");
NacosAiFactory.createAiService(props).queryAgentSpec("spec", null, null, null); Defensive patterns
Strategy: validation
Validate before calling
if (StringUtils.isBlank(properties.getProperty(PropertyKeyConst.SERVER_ADDR))) {
throw new IllegalStateException("serverAddr must be configured");
}
NacosAiFactory.createAiService(properties).queryAgentSpec(name, ver, label, md5); Try / catch
try {
aiService.queryAgentSpec(name, ver, label, md5);
} catch (NacosException e) {
if (e.getErrCode() == NacosException.INVALID_PARAM && "no server available".equals(e.getErrMsg())) {
log.error("No Nacos server configured");
}
} Prevention
- Always set serverAddr in client properties.
- Run a startup connectivity check.
When it happens
Trigger: Calling queryAgentSpec() when serverListManager.getServerList() returns an empty list. Same root cause as errors 621/623.
Common situations: Missing serverAddr in client properties. Server list initialization failed. Client started before any server was available.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/2832c724a6c3c64d.
Report an issue: GitHub.