1 commit 0dbaa252df906cc9c1d0dc7a075c16e039ab1c5b
2 Author: Willy Tarreau <w@1wt.eu>
3 Date: Tue Aug 21 15:35:31 2018 +0200
5 BUG/MEDIUM: cli/threads: protect some server commands against concurrent operations
7 The server-specific CLI commands "set weight", "set maxconn",
8 "disable agent", "enable agent", "disable health", "enable health",
9 "disable server" and "enable server" were not protected against
10 concurrent accesses. Now they take the server lock around the
13 This patch must be backported to 1.8.
15 (cherry picked from commit 3bcc2699ba08dd3971ae7a56631994b2524d2acb)
16 Signed-off-by: Willy Tarreau <w@1wt.eu>
18 diff --git a/src/server.c b/src/server.c
19 index 36a05e27..98dae535 100644
22 @@ -4299,6 +4299,10 @@ static int cli_parse_get_weight(char **args, struct appctx *appctx, void *privat
26 +/* Parse a "set weight" command.
28 + * Grabs the server lock.
30 static int cli_parse_set_weight(char **args, struct appctx *appctx, void *private)
33 @@ -4311,16 +4315,24 @@ static int cli_parse_set_weight(char **args, struct appctx *appctx, void *privat
37 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
39 warning = server_parse_weight_change_request(sv, args[3]);
41 appctx->ctx.cli.severity = LOG_ERR;
42 appctx->ctx.cli.msg = warning;
43 appctx->st0 = CLI_ST_PRINT;
46 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
51 -/* parse a "set maxconn server" command. It always returns 1. */
52 +/* parse a "set maxconn server" command. It always returns 1.
54 + * Grabs the server lock.
56 static int cli_parse_set_maxconn_server(char **args, struct appctx *appctx, void *private)
59 @@ -4333,16 +4345,24 @@ static int cli_parse_set_maxconn_server(char **args, struct appctx *appctx, void
63 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
65 warning = server_parse_maxconn_change_request(sv, args[4]);
67 appctx->ctx.cli.severity = LOG_ERR;
68 appctx->ctx.cli.msg = warning;
69 appctx->st0 = CLI_ST_PRINT;
72 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
77 -/* parse a "disable agent" command. It always returns 1. */
78 +/* parse a "disable agent" command. It always returns 1.
80 + * Grabs the server lock.
82 static int cli_parse_disable_agent(char **args, struct appctx *appctx, void *private)
85 @@ -4354,11 +4374,16 @@ static int cli_parse_disable_agent(char **args, struct appctx *appctx, void *pri
89 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
90 sv->agent.state &= ~CHK_ST_ENABLED;
91 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
95 -/* parse a "disable health" command. It always returns 1. */
96 +/* parse a "disable health" command. It always returns 1.
98 + * Grabs the server lock.
100 static int cli_parse_disable_health(char **args, struct appctx *appctx, void *private)
103 @@ -4370,11 +4395,16 @@ static int cli_parse_disable_health(char **args, struct appctx *appctx, void *pr
107 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
108 sv->check.state &= ~CHK_ST_ENABLED;
109 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
113 -/* parse a "disable server" command. It always returns 1. */
114 +/* parse a "disable server" command. It always returns 1.
116 + * Grabs the server lock.
118 static int cli_parse_disable_server(char **args, struct appctx *appctx, void *private)
121 @@ -4386,11 +4416,16 @@ static int cli_parse_disable_server(char **args, struct appctx *appctx, void *pr
125 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
126 srv_adm_set_maint(sv);
127 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
131 -/* parse a "enable agent" command. It always returns 1. */
132 +/* parse a "enable agent" command. It always returns 1.
134 + * Grabs the server lock.
136 static int cli_parse_enable_agent(char **args, struct appctx *appctx, void *private)
139 @@ -4409,11 +4444,16 @@ static int cli_parse_enable_agent(char **args, struct appctx *appctx, void *priv
143 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
144 sv->agent.state |= CHK_ST_ENABLED;
145 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
149 -/* parse a "enable health" command. It always returns 1. */
150 +/* parse a "enable health" command. It always returns 1.
152 + * Grabs the server lock.
154 static int cli_parse_enable_health(char **args, struct appctx *appctx, void *private)
157 @@ -4425,11 +4465,16 @@ static int cli_parse_enable_health(char **args, struct appctx *appctx, void *pri
161 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
162 sv->check.state |= CHK_ST_ENABLED;
163 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
167 -/* parse a "enable server" command. It always returns 1. */
168 +/* parse a "enable server" command. It always returns 1.
170 + * Grabs the server lock.
172 static int cli_parse_enable_server(char **args, struct appctx *appctx, void *private)
175 @@ -4441,11 +4486,13 @@ static int cli_parse_enable_server(char **args, struct appctx *appctx, void *pri
179 + HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
180 srv_adm_set_ready(sv);
181 if (!(sv->flags & SRV_F_COOKIESET)
182 && (sv->proxy->ck_opts & PR_CK_DYNAMIC) &&
184 srv_check_for_dup_dyncookie(sv);
185 + HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);