BUG/MINOR: server: do not keep an invalid dynamic server in px ids tree

A bug is present when trying to create a dynamic server with a fixed id.
If the server is detected invalid due to a later parsing arguments
error, the server is not removed from the proxy used ids tree before
being freed.

Change the mode of operation of 'id' keyword parsing handler. The
insertion in the backend tree is removed from the handler and is not
taken in charge by parse_server for configuration parsing. For the
dynamic servers, the insertion is called at the end of the 'add server'
CLI handler when the server has been validated.

This must be backported up to 2.4.

(cherry picked from commit 1613b4a75de04f110b7d5a09c1aebbf621c3811c)
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/server.c b/src/server.c
index 6f7c3d6..7d7953e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -610,7 +610,6 @@
 		return ERR_ALERT | ERR_FATAL;
 	}
 
-	eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
 	newsrv->flags |= SRV_F_FORCED_ID;
 	return 0;
 }
@@ -2721,6 +2720,15 @@
 	if (parse_flags & SRV_PARSE_TEMPLATE)
 		_srv_parse_tmpl_init(newsrv, curproxy);
 
+	/* If the server id is fixed, insert it in the proxy used_id tree.
+	 * This is needed to detect a later duplicate id via srv_parse_id.
+	 *
+	 * If no is specified, a dynamic one is generated in
+	 * check_config_validity.
+	 */
+	if (newsrv->flags & SRV_F_FORCED_ID)
+		eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
+
 	HA_DIAG_WARNING_COND((curproxy->cap & PR_CAP_LB) && !newsrv->uweight,
 	                     "parsing [%s:%d] : 'server %s' : configured with weight of 0 will never be selected by load balancing algorithms\n",
 	                     file, linenum, newsrv->id);
@@ -4470,10 +4478,8 @@
 	}
 
 	/* insert the server in the backend trees */
-	if (!(srv->flags & SRV_F_FORCED_ID)) {
-		eb32_insert(&be->conf.used_server_id, &srv->conf.id);
-		ebis_insert(&be->conf.used_server_name, &srv->conf.name);
-	}
+	eb32_insert(&be->conf.used_server_id, &srv->conf.id);
+	ebis_insert(&be->conf.used_server_name, &srv->conf.name);
 
 	thread_release();