diff --git a/include/haproxy/server.h b/include/haproxy/server.h index e8e00a5e7..ad5baef34 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -370,6 +370,8 @@ static inline void srv_detach(struct server *srv) prev->next = srv->next; } + /* reset the proxy's ready_srv if it was this one */ + HA_ATOMIC_CAS(&px->ready_srv, &srv, NULL); } /* Returns a pointer to the first server matching id in backend . diff --git a/src/server.c b/src/server.c index 2487e13ee..60d138c95 100644 --- a/src/server.c +++ b/src/server.c @@ -7151,8 +7151,10 @@ static void srv_update_status(struct server *s, int type, int cause) * If the server is no longer running, let's not pretend * it can handle requests. */ - if (s->cur_state != SRV_ST_RUNNING && s->proxy->ready_srv == s) - HA_ATOMIC_STORE(&s->proxy->ready_srv, NULL); + if (s->cur_state != SRV_ST_RUNNING) { + struct server *srv = s; + HA_ATOMIC_CAS(&s->proxy->ready_srv, &srv, NULL); + } s->last_change = ns_to_sec(now_ns); if (s->counters.shared.tg[tgid - 1])