]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: peers: do not clear the alive flag of a replacement session
authorHyeonggeun Oh <hyeonggeun.oh@plaintexting.com>
Mon, 30 Nov 2026 16:31:20 +0000 (16:31 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 1 Dec 2026 10:52:21 +0000 (11:52 +0100)
When an incoming connection supersedes an established session with the
same peer, the old applet is shut down with peer_session_forceshutdown(),
then the new one is installed and the peer is flagged PEER_F_ALIVE. But
when the old applet is released later, peer_session_release() clears
PEER_F_ALIVE unconditionally, even though the applet does not own the
peer anymore. The collision delay before the next liveness check is 50 to
2049ms while the first heartbeat is due after 3s, so the sync task finds
the replacement not alive and kills it.

The liveness is tracked per session, so clear the flag in
__peer_session_deinit(), which is only called for the applet owning the
peer, instead of on every applet release. In the collision path, the
deinit happens before the new session is flagged, so the order is
preserved.

This should fix GH issue #3519. It must be backported to all stable
versions.

Signed-off-by: Hyeonggeun Oh <hyeonggeun.oh@plaintexting.com>
src/peers.c

index d242582e84607c282a1252aeb76249437f4b7b0f..b8a6c68859f10089fc3db983f60905ca0d101c77 100644 (file)
@@ -1159,8 +1159,8 @@ void __peer_session_deinit(struct peer *peer)
                st->remote_data = 0;
        }
 
-        /* reset teaching flags to 0 */
-        peer->flags &= ~PEER_TEACH_FLAGS;
+       /* reset teaching and alive flags */
+        peer->flags &= ~(PEER_TEACH_FLAGS|PEER_F_ALIVE);
 
        /* Mark the peer as stopping and wait for the sync task */
        peer->flags |= PEER_F_WAIT_SYNCTASK_ACK;
@@ -1234,7 +1234,6 @@ static void peer_session_release(struct appctx *appctx)
                HA_SPIN_LOCK(PEER_LOCK, &peer->lock);
                if (peer->appctx == appctx)
                        __peer_session_deinit(peer);
-               peer->flags &= ~PEER_F_ALIVE;
                HA_SPIN_UNLOCK(PEER_LOCK, &peer->lock);
                TRACE_STATE("peer session released", PEERS_EV_SESS_END, appctx, peer);
        }