AvaticaClientRuntimeException: Remote driver error: ISE: Too many connections, limit is[25]

HI,

druid  sql :

Properties connectionProperties = new Properties();
String url = "jdbc:avatica:remote:url=http://locahost:8082/druid/v2/sql/avatica/";
LOGGER.info("url:{}", url);
try {
    Connection connection = DriverManager.getConnection(url, connectionProperties);
    server.set(connection);
} catch (SQLException e) {
    LOGGER.error("创建druid jdbc连接过程中出现异常:", e);
}

AvaticaClientRuntimeException: Remote driver error: ISE: Too many connections, limit is[25]
. Error -1 (00000) UNKNOWN

io.druid.java.util.common.ISE: Too many connections, limit is[25]
	at io.druid.sql.avatica.DruidMeta.openDruidConnection(DruidMeta.java:504)
	at io.druid.sql.avatica.DruidMeta.openConnection(DruidMeta.java:95)
	at org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:299)
	at org.apache.calcite.avatica.remote.Service$OpenConnectionRequest.accept(Service.java:1750)
	at org.apache.calcite.avatica.remote.Service$OpenConnectionRequest.accept(Service.java:1730)
	at org.apache.calcite.avatica.remote.AbstractHandler.apply(AbstractHandler.java:95)
	at org.apache.calcite.avatica.remote.JsonHandler.apply(JsonHandler.java:52)
	at org.apache.calcite.avatica.server.AvaticaJsonHandler.handle(AvaticaJsonHandler.java:129)
	at io.druid.sql.avatica.DruidAvaticaHandler.handle(DruidAvaticaHandler.java:63)
	at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
	at org.eclipse.jetty.server.Server.handle(Server.java:534)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
	at java.lang.Thread.run(Thread.java:745)

	at org.apache.calcite.avatica.remote.Service$ErrorResponse.toException(Service.java:2476)
	at org.apache.calcite.avatica.remote.JsonService.decode(JsonService.java:55)
	at org.apache.calcite.avatica.remote.JsonService.apply(JsonService.java:172)
	at org.apache.calcite.avatica.remote.Driver.connect(Driver.java:176)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
	at com.druid.QueryTest112.groupBy(QueryTest112.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

It means that there are too many concurrent connections open. There’s a limit since each one requires some resources on the broker to keep open. If you need more than the default, you can raise druid.sql.avatica.maxConnections. Also make sure you’re using Druid 0.10.1, since it has some improvements around cleaning up stale connections that will help here.