usec_t last_lifetime_disconnect;/* last time when server_lifetime was applied */
- /* if last connect failed, there should be delay before next */
+ /* if last connect to server failed, there should be delay before next */
usec_t last_connect_time;
unsigned last_connect_failed:1;
unsigned last_login_failed:1;
}
/*
- * Don't let clients queue at all, if there is no working server connection.
+ * Don't let clients queue at all if there is no working server connection.
*
* It must still allow following cases:
* - empty pool on startup
* - new server connections fail due to server_connect_timeout, or other failure
*
* So here we drop client if all server connections have been dropped
- * and new one's fail.
+ * and new ones fail.
+ *
+ * Return true if the client connection should be allowed, false if it
+ * should be rejected.
*/
bool check_fast_fail(PgSocket *client)
{
int cnt;
PgPool *pool = client->pool;
- /* reject if no servers are available and the last login failed */
+ /* If last login succeeded, client can go ahead. */
if (!pool->last_login_failed)
return true;
+
+ /* If there are servers available, client can go ahead. */
cnt = pool_server_count(pool) - statlist_count(&pool->new_server_list);
if (cnt)
return true;
+
+ /* Else we fail the client. */
disconnect_client(client, true, "pgbouncer cannot connect to server");
- /* usual relaunch won't work, as there are no waiting clients */
+ /*
+ * Try to launch a new connection. (launch_new_connection()
+ * will check for server_login_retry etc.) The usual relaunch
+ * from janitor.c won't do anything, as there are no waiting
+ * clients, so we need to do it here to get any new servers
+ * eventually.
+ */
launch_new_connection(pool);
return false;
if (pool->last_connect_failed) {
usec_t now = get_cached_time();
if (now - pool->last_connect_time < cf_server_login_retry) {
- log_debug("launch_new_connection: last failed, wait");
+ log_debug("launch_new_connection: last failed, not launching new connection yet, still waiting %" PRIu64 " s",
+ (cf_server_login_retry - (now - pool->last_connect_time)) / USEC);
return;
}
}