/* unused : 0x00004000 */
#define PEER_F_ST_RELEASED 0x00008000 /* Used to set a peer in released state. */
#define PEER_F_RESYNC_REQUESTED 0x00010000 /* A resnyc was explicitly requested */
+
+#define PEER_F_WAIT_SYNCTASK_ACK 0x00020000 /* Stop all processing waiting for the sync task acknowledgement when the applet state changes */
+
/* unused : 0x00020000..0x10000000 */
#define PEER_F_ALIVE 0x20000000 /* Used to flag a peer a alive. */
#define PEER_F_HEARTBEAT 0x40000000 /* Heartbeat message to send. */
/* Mark peer as released */
peer->flags &= PEER_STATE_RESET;
- peer->flags |= PEER_F_ST_RELEASED;
+ peer->flags |= (PEER_F_ST_RELEASED|PEER_F_WAIT_SYNCTASK_ACK);
task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
}
peer->flags &= PEER_TEACH_RESET;
peer->flags &= PEER_STATE_RESET;
- peer->flags |= PEER_F_ST_ACCEPTED;
+ peer->flags |= (PEER_F_ST_ACCEPTED|PEER_F_WAIT_SYNCTASK_ACK);
/* Init cursors */
for (st = peer->tables; st ; st = st->next) {
}
peer->flags &= PEER_STATE_RESET;
- peer->flags |= PEER_F_ST_CONNECTED;
+ peer->flags |= (PEER_F_ST_CONNECTED|PEER_F_WAIT_SYNCTASK_ACK);
}
/*
}
}
- if (curpeer->flags & (PEER_F_ST_RELEASED|PEER_F_ST_ACCEPTED|PEER_F_ST_CONNECTED))
+ if (curpeer->flags & PEER_F_WAIT_SYNCTASK_ACK)
goto out;
reql = peer_recv_msg(appctx, (char *)msg_head, sizeof msg_head, &msg_len, &totl);
__process_peer_learn_status(peers, ps);
__process_peer_state(peers, ps);
+ /* Peer changes, if any, were now ack by the sync task. Unblock
+ * the peer (any wakeup should already be performed, no need to
+ * do it here)
+ */
+ ps->flags &= ~PEER_F_WAIT_SYNCTASK_ACK;
+
/* For each remote peers */
if (!ps->local) {
if (!ps->appctx) {
__process_peer_learn_status(peers, ps);
__process_peer_state(peers, ps);
+ /* Peer changes, if any, were now ack by the sync task. Unblock
+ * the peer (any wakeup should already be performed, no need to
+ * do it here)
+ */
+ ps->flags &= ~PEER_F_WAIT_SYNCTASK_ACK;
+
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