1 commit 1c95076d881b7508a8d0819b1cfd642e364b255c
2 Author: Jérôme Magnin <jmagnin@haproxy.com>
3 Date: Sun Jan 20 11:27:40 2019 +0100
5 BUG/MINOR: server: don't always trust srv_check_health when loading a server state
7 When we load health values from a server state file, make sure what we assign
8 to srv->check.health actually matches the state we restore.
10 This should be backported as far as 1.6.
12 (cherry picked from commit f57afa453a685cfd92b7a27ef6e6035cb384ff57)
13 Signed-off-by: Willy Tarreau <w@1wt.eu>
14 (cherry picked from commit 75455a0b78ce4ac723698df26c014b38467843b1)
15 Signed-off-by: William Lallemand <wlallemand@haproxy.org>
17 diff --git a/src/server.c b/src/server.c
18 index a86db3db..28414780 100644
21 @@ -2843,16 +2843,37 @@ static void srv_update_state(struct server *srv, int version, char **params)
22 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
23 /* recover operational state and apply it to this server
24 * and all servers tracking this one */
25 + srv->check.health = srv_check_health;
26 switch (srv_op_state) {
28 srv->check.health = 0;
29 srv_set_stopped(srv, "changed from server-state after a reload", NULL);
32 + /* If rise == 1 there is no STARTING state, let's switch to
35 + if (srv->check.rise == 1) {
36 + srv->check.health = srv->check.rise + srv->check.fall - 1;
37 + srv_set_running(srv, "", NULL);
40 + if (srv->check.health < 1 || srv->check.health >= srv->check.rise)
41 + srv->check.health = srv->check.rise - 1;
42 srv->next_state = srv_op_state;
45 - srv->check.health = srv->check.rise + srv->check.fall - 1;
46 + /* If fall == 1 there is no STOPPING state, let's switch to
49 + if (srv->check.fall == 1) {
50 + srv->check.health = 0;
51 + srv_set_stopped(srv, "changed from server-state after a reload", NULL);
54 + if (srv->check.health < srv->check.rise ||
55 + srv->check.health > srv->check.rise + srv->check.fall - 2)
56 + srv->check.health = srv->check.rise;
57 srv_set_stopping(srv, "changed from server-state after a reload", NULL);
60 @@ -2906,7 +2927,6 @@ static void srv_update_state(struct server *srv, int version, char **params)
61 srv->last_change = date.tv_sec - srv_last_time_change;
62 srv->check.status = srv_check_status;
63 srv->check.result = srv_check_result;
64 - srv->check.health = srv_check_health;
66 /* Only case we want to apply is removing ENABLED flag which could have been
67 * done by the "disable health" command over the stats socket