public void returnConnection(final Connection connection) throws ConnectionException {
        logger.debug("Attempting to return {} on {}", connection, host);
        if (isClosed()) throw new ConnectionException(host.getHostUri(), host.getAddress(), "Pool is shutdown");

        connection.isBorrowed().set(false);

        if (connection.isDead()) {
            logger.debug("Marking {} as dead", this.host);
            this.replaceConnection(connection);
        } else {
            if (bin.contains(connection)) {
                logger.debug("{} is already in the bin and it has no inflight requests so it is safe to close", connection);
                if (bin.remove(connection))
                    connection.closeAsync();
                return;
            }

            // Destroy any extra connections that exceeded the maximum pool size. Idle connections will be removed
            // based on their idle timeout so that isn't handled here.
            final int poolSize = connections.size();
            if (poolSize > maxPoolSize) {
                if (logger.isDebugEnabled())
                    logger.debug("destroy {}", connection.getConnectionInfo());
                destroyConnection(connection);
            } else {
                logger.debug("Pool size is {} - returning connection to pool: {}", poolSize, connection);
                availableConnections.add(connection);
                announceAvailableConnection();
            }
        }
    }
The result of a connection attempt. A null value for failureCause means that the connection attempt was successful.
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java