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>
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;
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);
}