MyCATApache/Mycat-Server · error · IOException
the max activeConnnections size can not be max than…
Error message
the max activeConnnections size can not be max than maxconnections
What it means
PhysicalDatasource.getConnection creates a new backend connection only when the pool is under both its max active and max total connection limits; otherwise it logs and throws IOException 'the max activeConnnections size can not be max than maxconnections'. It means the datasource has exhausted its allowed connection capacity, so no new connection can be handed out for the requested schema.
Solutions
- Increase the dataHost maxCon in schema.xml (and ensure MySQL server max_connections is high enough) and reload.
- Fix connection leaks: ensure queries close/return backend connections; check for long-running transactions holding connections.
- Add read hosts or split load across more dataNodes to reduce per-pool pressure.
- Catch IOException in the request path and apply backoff/retry or return 'too many connections' to the client.
Example fix
// before <dataHost name="host1" maxCon="100" minCon="10" balance="0" switchType="1"> // after (under load, raise limits) <dataHost name="host1" maxCon="1000" minCon="50" balance="1" switchType="1">
Defensive patterns
Strategy: retry
Validate before calling
if (ds.getActiveCount() >= ds.getMaxCon()) {
throw new IllegalStateException("pool " + ds.getName() + " exhausted (" + ds.getActiveCount() + "/" + ds.getMaxCon() + ")");
} Type guard
boolean hasCapacity(PhysicalDatasource ds) {
return ds.getActiveCount() < ds.getMaxCon() && ds.getTotalConnectionCount() < ds.getMaxConnections();
} Try / catch
try {
ds.getConnection(schema, autocommit, handler, attachment);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("max activeConnnections")) {
Thread.sleep(backoffMs);
ds.getConnection(schema, autocommit, handler, attachment);
} else { throw e; }
} Prevention
- Size dataHost maxCon against peak concurrency and MySQL server max_connections.
- Watch pool metrics (active vs total connections) and alert before saturation.
- Audit for backend connection leaks (unclosed statements/transactions).
- Spread load across more read hosts/dataNodes instead of growing one pool.
When it happens
Trigger: Any connection-request path (getConnection, getRWBanlanceCon, getReadBanlanceCon, getReadCon, initSource, getConnectionFromSameSource) when there are no idle connections and the pool's active count has reached the configured max connections limit, so createNewConnection is refused.
Common situations: Under-provisioned dataHost max connections vs workload; connection leaks (backend connections never returned); many concurrent Mycat sessions hitting one shard; low backend MySQL max_connections leaving connections stuck.
Related errors
- can't find existing connection,maybe fininshed
- Invalid DataSource
- The ring buffer cannot accommodate
- There is no space for new record
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/1396f9d88da13de2.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/backend/datasource/PhysicalDatasource.java:568
// curTotalConnection = this.totalConnection.get(); //CAS更新失败,则重新判断当前连接是否超过最大连接数
//
// }
//
// // 如果后端连接不足,立即失败,故直接抛出连接数超过最大连接异常
// LOGGER.error("the max activeConnnections size can not be max than maxconnections:" + curTotalConnection);
// throw new IOException("the max activeConnnections size can not be max than maxconnections:" + curTotalConnection);
// 当前最大连接
long activeCons = increamentCount.longValue()+totalConnectionCount;
if (activeCons < size) {// 下一个连接大于最大连接数
//提前increamentCount的操作
increamentCount.increment();
LOGGER.info("no ilde connection in pool "+System.identityHashCode(this)+" ,create new connection for " + this.name + " of schema " + schema + " totalConnectionCount: " + totalConnectionCount + " increamentCount: "+increamentCount);
createNewConnection(handler, attachment, schema);
} else { // create connection
LOGGER.error("the max activeConnnections size can not be max than maxconnections");
throw new IOException("the max activeConnnections size can not be max than maxconnections");
}
}
}
/**
* 是否超过最大连接数
* @return
*/
// private boolean exceedMaxConnections() {
// return this.totalConnection.get() + 1 > size;
// }
//
// public int decrementActiveCountSafe() {
// return this.activeCount.decrementAndGet();
// }
//
// public int incrementActiveCountSafe() {
// return this.activeCount.incrementAndGet();View on GitHub (pinned to 65f8d8beb7)