From: Aki Tuomi Date: Mon, 10 May 2021 21:07:24 +0000 (+0300) Subject: auth: auth-worker - Respect service_count X-Git-Tag: 2.3.16~131 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef2a1b233615a7d933d2bd85cc2bbdd7ffececf7;p=thirdparty%2Fdovecot%2Fcore.git auth: auth-worker - Respect service_count If service_count is set, then auth-worker will stop after given number of requests. --- diff --git a/src/auth/auth-settings.c b/src/auth/auth-settings.c index 241e775b63..4268b9a7ce 100644 --- a/src/auth/auth-settings.c +++ b/src/auth/auth-settings.c @@ -93,7 +93,7 @@ struct service_settings auth_worker_service_settings = { .process_min_avail = 0, .process_limit = 0, .client_limit = 1, - .service_count = 1, + .service_count = 0, .idle_kill = 0, .vsz_limit = UOFF_T_MAX, diff --git a/src/auth/auth-worker-client.c b/src/auth/auth-worker-client.c index a358857ee0..ff88bc2ed9 100644 --- a/src/auth/auth-worker-client.c +++ b/src/auth/auth-worker-client.c @@ -24,6 +24,9 @@ #define CLIENT_STATE_IDLE "idling" #define CLIENT_STATE_STOP "waiting for shutdown" +static unsigned int auth_worker_max_service_count = 0; +static unsigned int auth_worker_service_count = 0; + struct auth_worker_client { struct connection conn; int refcount; @@ -56,6 +59,11 @@ static int auth_worker_output(struct auth_worker_client *client); static void auth_worker_client_destroy(struct connection *conn); static void auth_worker_client_unref(struct auth_worker_client **_client); +void auth_worker_set_max_service_count(unsigned int count) +{ + auth_worker_max_service_count = count; +} + static struct auth_worker_client *auth_worker_get_client(void) { if (!auth_worker_has_client()) @@ -791,6 +799,13 @@ auth_worker_client_input_args(struct connection *conn, const char *const *args) client->refcount++; e_debug(cmd->event, "Handling %s request", args[1]); + /* Check if we have reached service_count */ + if (auth_worker_max_service_count > 0) { + auth_worker_service_count++; + if (auth_worker_service_count >= auth_worker_max_service_count) + worker_restart_request = TRUE; + } + auth_worker_refresh_proctitle(args[1]); if (strcmp(args[1], "PASSV") == 0) ret = auth_worker_handle_passv(cmd, id, args + 2, &error); diff --git a/src/auth/auth-worker-client.h b/src/auth/auth-worker-client.h index 276574d4ef..e41ee83aab 100644 --- a/src/auth/auth-worker-client.h +++ b/src/auth/auth-worker-client.h @@ -21,4 +21,7 @@ void auth_worker_client_send_shutdown(void); void auth_worker_connections_destroy_all(void); +/* Stop master service after this many requests. 0 is unlimited. */ +void auth_worker_set_max_service_count(unsigned int count); + #endif diff --git a/src/auth/main.c b/src/auth/main.c index 7fa6bb0cee..485b71d870 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -247,6 +247,10 @@ static void main_init(void) /* workers have only a single connection from the master auth process */ master_service_set_client_limit(master_service, 1); + auth_worker_set_max_service_count( + master_service_get_service_count(master_service)); + /* make sure this process cycles if auth connection drops */ + master_service_set_service_count(master_service, 1); } else { /* caching is handled only by the main auth process */ passdb_cache_init(global_auth_settings);