]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Avoid delaying reply when shutting down
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 11 Feb 2025 14:19:05 +0000 (16:19 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 13 Feb 2025 21:49:45 +0000 (21:49 +0000)
src/auth/auth-request-handler.c
src/auth/auth-request.c
src/auth/auth.c
src/auth/auth.h
src/auth/main.c

index 8a595c1045ca2a44112582e4b6e5c89c27016ee5..f71dcef6c907f5b6e9ca8ed95afcb01b6b2262f1 100644 (file)
@@ -235,7 +235,7 @@ auth_request_handle_failure(struct auth_request *request, const char *reply)
 
        e_debug(request->event, "handling failure, nodelay=%d",
                (int) request->failure_nodelay);
-       if (request->failure_nodelay) {
+       if (request->failure_nodelay || shutting_down) {
                /* passdb specifically requested not to delay the reply. */
                handler->callback(reply, handler->conn);
                auth_request_unref(&request);
index 7ac368114e46dd6218a7d280302b9977e141d96c..c20a35cad79a7920b6c0feb1ffa621bdaf7b74eb 100644 (file)
@@ -782,6 +782,9 @@ void auth_request_userdb_lookup_end(struct auth_request *request,
 static unsigned int
 auth_request_get_internal_failure_delay(struct auth_request *request)
 {
+       if (shutting_down)
+               return 0;
+
        unsigned int delay_msecs = request->set->internal_failure_delay;
 
        /* add 0..50% random delay to avoid thundering herd problems */
@@ -1223,7 +1226,7 @@ static void auth_request_policy_check_callback(int result, void *context)
                /* fail it right here and now */
                auth_request_fail(ctx->request);
        } else if (ctx->type != AUTH_POLICY_CHECK_TYPE_SUCCESS && result > 0 &&
-                  !ctx->request->fields.no_penalty) {
+                  !ctx->request->fields.no_penalty && !shutting_down) {
                ctx->request->to_penalty = timeout_add(result * 1000,
                        auth_request_policy_penalty_finish, context);
        } else {
index 9097982e13672936466e57df714b30bc4fda84d4..a8fbab3d776a958419a1d13667808cbacfd75a15 100644 (file)
@@ -16,6 +16,8 @@
 #define AUTH_DNS_IDLE_TIMEOUT_MSECS (1000*60)
 #define AUTH_DNS_CACHE_TTL_SECS 10
 
+bool shutting_down = FALSE;
+
 struct event *auth_event;
 struct event_category event_category_auth = {
        .name = "auth",
index d1c1b96c1c1d9342571f5f255be0209b154e8040..cfde068679139aed7723d2f6a774a0f691de8a86 100644 (file)
@@ -84,6 +84,7 @@ struct auth {
        struct dns_client *dns_client;
 };
 
+extern bool shutting_down;
 
 struct auth *auth_find_protocol(const char *name);
 struct auth *auth_default_protocol(void);
index 9810c96cf20f35d8eeabe3b88e99c0957b0760e4..e6f7b805ff1f93cab898dfd22a762078c6c3b622 100644 (file)
@@ -249,6 +249,7 @@ static void main_deinit(void)
 {
        struct auth_socket_listener *l;
 
+       shutting_down = TRUE;
        if (auth_penalty != NULL) {
                /* cancel all pending anvil penalty lookups */
                auth_penalty_deinit(&auth_penalty);