From: Christopher Faulet Date: Fri, 22 Mar 2024 13:51:24 +0000 (+0100) Subject: MINOR: peers: sligthly adapt part processing the stopping signal X-Git-Tag: v3.0-dev8~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a16560315309845c3197e48e6447d2c1ab0f197;p=thirdparty%2Fhaproxy.git MINOR: peers: sligthly adapt part processing the stopping signal The signal and the PEERS_F_DONOTSTOP flag are now handled in the loop on peers to force sessions shutdown. We will need to loop on all peers to update their state. It is easier this way. --- diff --git a/src/peers.c b/src/peers.c index 5a4a594528..8d4377f696 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3583,28 +3583,27 @@ static void __process_stopping_peer_sync(struct task *task, struct peers *peers, for (ps = peers->remote; ps; ps = ps->next) HA_SPIN_LOCK(PEER_LOCK, &ps->lock); + /* For each peer */ + for (ps = peers->remote; ps; ps = ps->next) { + if ((state & TASK_WOKEN_SIGNAL) && !(peers->flags & PEERS_F_DONOTSTOP)) { + /* we're killing a connection, we must apply a random delay before + * retrying otherwise the other end will do the same and we can loop + * for a while. + */ + ps->reconnect = tick_add(now_ms, MS_TO_TICKS(50 + ha_random() % 2000)); + if (ps->appctx) { + peer_session_forceshutdown(ps); + } + } + } + + /* We've just received the signal */ if (state & TASK_WOKEN_SIGNAL) { - /* We've just received the signal */ if (!(peers->flags & PEERS_F_DONOTSTOP)) { /* add DO NOT STOP flag if not present */ _HA_ATOMIC_INC(&jobs); peers->flags |= PEERS_F_DONOTSTOP; - /* disconnect all connected peers to process a local sync - * this must be done only the first time we are switching - * in stopping state - */ - for (ps = peers->remote; ps; ps = ps->next) { - /* we're killing a connection, we must apply a random delay before - * retrying otherwise the other end will do the same and we can loop - * for a while. - */ - ps->reconnect = tick_add(now_ms, MS_TO_TICKS(50 + ha_random() % 2000)); - if (ps->appctx) { - peer_session_forceshutdown(ps); - } - } - /* Set resync timeout for the local peer and request a immediate reconnect */ peers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(PEER_RESYNC_TIMEOUT)); peers->local->reconnect = now_ms;