BUG/MINOR: server: remove srv from px list on CLI 'add server' error
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 4 Aug 2021 09:20:05 +0000 (11:20 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 4 Aug 2021 12:57:06 +0000 (14:57 +0200)
If an error occured during the CLI 'add server' handler, the newly
created server must be removed from the proxy list if already inserted.
Currently, this can happen on the extremely rare error during server id
generation if there is no id left.

The removal operation is not thread-safe, it must be conducted before
releasing the thread isolation.

This can be backported up to 2.4. Please note that dynamic server track
is not implemented in 2.4, so the release_server_track invocation must
be removed for the backport to prevent a compilation error.

src/server.c

index d5fceb9..22d0fff 100644 (file)
@@ -4589,8 +4589,23 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
        return 0;
 
 out:
-       if (srv && srv->track)
-               release_server_track(srv);
+       if (srv) {
+               if (srv->track)
+                       release_server_track(srv);
+
+               /* remove the server from the proxy linked list */
+               if (be->srv == srv) {
+                       be->srv = srv->next;
+               }
+               else {
+                       struct server *prev;
+                       for (prev = be->srv; prev && prev->next != srv; prev = prev->next)
+                               ;
+                       if (prev)
+                               prev->next = srv->next;
+               }
+
+       }
 
        thread_release();