]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: acme: register the task in the ckch_store
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 16 Apr 2025 15:12:43 +0000 (17:12 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 16 Apr 2025 15:12:43 +0000 (17:12 +0200)
This patch registers the task in the ckch_store so we don't run 2 tasks
at the same time for a given certificate.

Move the task creation under the lock and check if there was already a
task under the lock.

include/haproxy/ssl_ckch-t.h
src/acme.c

index 01f9720458b60aa46fcb83138adb0fcd004cd35a..00a1d729bf6c6f7cc8d59c04d633842434ae9a7e 100644 (file)
@@ -87,6 +87,7 @@ struct ckch_store {
        struct list ckch_inst; /* list of ckch_inst which uses this ckch_node */
        struct list crtlist_entry; /* list of entries which use this store */
        struct ckch_conf conf;
+       struct task *acme_task;
        struct ebmb_node node;
        char path[VAR_ARRAY];
 };
index 86199288c0468a27d9b82bbeffc3a4b87aa437f0..47520a738e87fe4175bdf0eb13d502abc3823972 100644 (file)
@@ -1789,6 +1789,11 @@ static int cli_acme_renew_parse(char **args, char *payload, struct appctx *appct
                goto err;
        }
 
+       if (store->acme_task != NULL) {
+               memprintf(&err, "An ACME task is already running for certificate '%s'.\n", args[2]);
+               goto err;
+       }
+
        if (store->conf.acme.id == NULL) {
                memprintf(&err, "No ACME configuration defined for file '%s'.\n", args[2]);
                goto err;
@@ -1806,6 +1811,18 @@ static int cli_acme_renew_parse(char **args, char *payload, struct appctx *appct
                goto err;
        }
 
+
+       task = task_new_anywhere();
+       if (!task)
+               goto err;
+       task->nice = 0;
+       task->process = acme_process;
+
+        /* register the task in the store so we don't
+        * have 2 tasks at the same time
+        */
+        store->acme_task = task;
+
        HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
 
        ctx = calloc(1, sizeof *ctx);
@@ -1855,15 +1872,8 @@ static int cli_acme_renew_parse(char **args, char *payload, struct appctx *appct
                goto err;
        }
 
-
        ctx->store = newstore;
        ctx->cfg = cfg;
-
-       task = task_new_anywhere();
-       if (!task)
-               goto err;
-       task->nice = 0;
-       task->process = acme_process;
        task->context = ctx;
 
        task_wakeup(task, TASK_WOKEN_INIT);