]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: auth-worker - Respect service_count
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 10 May 2021 21:07:24 +0000 (00:07 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 21 May 2021 05:47:56 +0000 (05:47 +0000)
If service_count is set, then auth-worker will stop after
given number of requests.

src/auth/auth-settings.c
src/auth/auth-worker-client.c
src/auth/auth-worker-client.h
src/auth/main.c

index 241e775b63c98dd0a91dfc6d5d5a969dc39f8ece..4268b9a7ceeaddb6b59caff5e9dc2c91011dd32a 100644 (file)
@@ -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,
 
index a358857ee0eef14c9a5ca8a7dcf5aee123cb172b..ff88bc2ed95078d19c640539119cc723e2f967dd 100644 (file)
@@ -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);
index 276574d4ef4cbfd2bf40e35042b83b8dfad1e301..e41ee83aab78a611e38cbf35cad3cfb220915710 100644 (file)
@@ -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
index 7fa6bb0cee5e198be9cfa697e3201fda7964e762..485b71d870ceaffd9bfecbff92db3d1277ee24e2 100644 (file)
@@ -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);