Generic connection pool logic