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 <[email protected]> --- src/peers.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/peers.c b/src/peers.c index d242582e8..b827e9848 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1162,6 +1162,12 @@ void __peer_session_deinit(struct peer *peer) /* reset teaching flags to 0 */ peer->flags &= ~PEER_TEACH_FLAGS; + /* the liveness is tracked per session. It is cleared here, and not + * when an applet is released, since a superseded applet may only be + * released once its replacement was already marked alive. + */ + peer->flags &= ~PEER_F_ALIVE; + /* Mark the peer as stopping and wait for the sync task */ peer->flags |= PEER_F_WAIT_SYNCTASK_ACK; peer->appstate = PEER_APP_ST_STOPPING; @@ -1234,7 +1240,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); } -- 2.52.0

