{"record":{"id":"1396f9d88da13de2","repo":"MyCATApache/Mycat-Server","slug":"the-max-activeconnnections-size-can-not-be-max-tha","errorCode":null,"errorMessage":"the max activeConnnections size can not be max than maxconnections","messagePattern":"the max activeConnnections size can not be max than maxconnections","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/datasource/PhysicalDatasource.java","lineNumber":568,"sourceCode":"//\t\t\t\tcurTotalConnection = this.totalConnection.get(); //CAS更新失败，则重新判断当前连接是否超过最大连接数\n//\t\t\t\t\n//\t\t\t}\n//\t\t\t\n//\t\t\t// 如果后端连接不足，立即失败,故直接抛出连接数超过最大连接异常\n//\t\t\tLOGGER.error(\"the max activeConnnections size can not be max than maxconnections:\" + curTotalConnection);\n//\t\t\tthrow new IOException(\"the max activeConnnections size can not be max than maxconnections:\" + curTotalConnection);\n\n\n\t\t\t// 当前最大连接\n\t\t\tlong activeCons = increamentCount.longValue()+totalConnectionCount;\n\t\t\tif (activeCons < size) {// 下一个连接大于最大连接数\n\t\t\t\t//提前increamentCount的操作\n\t\t\t\tincreamentCount.increment();\n\t\t\t\tLOGGER.info(\"no ilde connection in pool \"+System.identityHashCode(this)+\" ,create new connection for \"\t+ this.name + \" of schema \" + schema + \" totalConnectionCount: \" + totalConnectionCount + \" increamentCount: \"+increamentCount);\n\t\t\t\tcreateNewConnection(handler, attachment, schema);\n\t\t\t} else { // create connection\n\t\t\t\tLOGGER.error(\"the max activeConnnections size can not be max than maxconnections\");\n\t\t\t\tthrow new IOException(\"the max activeConnnections size can not be max than maxconnections\");\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/**\n\t * 是否超过最大连接数\n\t * @return\n\t */\n//\tprivate boolean exceedMaxConnections() {\n//\t\treturn this.totalConnection.get() + 1 > size;\n//\t}\n//\t\n//\tpublic int decrementActiveCountSafe() {\n//\t\treturn this.activeCount.decrementAndGet();\n//\t}\n//\t\n//\tpublic int incrementActiveCountSafe() {\n//\t\treturn this.activeCount.incrementAndGet();","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/datasource/PhysicalDatasource.java#L550-L586","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n<dataHost name=\"host1\" maxCon=\"100\" minCon=\"10\" balance=\"0\" switchType=\"1\">\n// after (under load, raise limits)\n<dataHost name=\"host1\" maxCon=\"1000\" minCon=\"50\" balance=\"1\" switchType=\"1\">","handlingStrategy":"retry","validationCode":"if (ds.getActiveCount() >= ds.getMaxCon()) {\n    throw new IllegalStateException(\"pool \" + ds.getName() + \" exhausted (\" + ds.getActiveCount() + \"/\" + ds.getMaxCon() + \")\");\n}","typeGuard":"boolean hasCapacity(PhysicalDatasource ds) {\n    return ds.getActiveCount() < ds.getMaxCon() && ds.getTotalConnectionCount() < ds.getMaxConnections();\n}","tryCatchPattern":"try {\n    ds.getConnection(schema, autocommit, handler, attachment);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"max activeConnnections\")) {\n        Thread.sleep(backoffMs);\n        ds.getConnection(schema, autocommit, handler, attachment);\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["connection-pool","resource-exhaustion","capacity","io-exception"],"backgroundTag":"rate-limit-exceeded","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}