Details
Description
When the gremlin driver is used with an important number of concurrent requests, sockets are opened far beyond the max pool size.
At some point, the connections are destroyed, the pool is empty and then the borrowConnection process goes through :
if (connections.isEmpty()) { logger.debug("Tried to borrow connection but the pool was empty for {} - scheduling pool creation and waiting for connection", host); for (int i = 0; i < minPoolSize; i++) { scheduledForCreation.incrementAndGet(); newConnection(); } return waitForConnection(timeout, unit); }
If many connections are borrowed at the same time then this code will schedule as many connections for creation.
I added a check :
for (int i = 0; i < minPoolSize; i++) { if (scheduledForCreation.get() < minPoolSize) { scheduledForCreation.incrementAndGet(); logger.debug("borrowConnection: [inc] scheduledForCreation=" + scheduledForCreation.get()); newConnection(); } }
It seems to solve the problem.