From d4f8286e45618fa1017c79e32950487f1d1ad4d4 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 28 Jul 2023 14:03:27 +0000 Subject: [PATCH] MEDIUM: peers: drop then re-acquire the wrlock in peer_send_teachmsgs() This function maintains the write lock for a while. In practice it does not need to hold it that long, and some parts could be performed under a read lock. This patch first drops then re-acquires the write lock at the function's entry. The purpose is simply to break the end-to-end atomicity to prove that it has no impact in case something needs to be bisected later. In fact the write lock is already dropped while calling peer_send_updatemsg(). --- src/peers.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/peers.c b/src/peers.c index c7c28b1ee..23f6e5d12 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1575,8 +1575,10 @@ static inline int peer_send_teachmsgs(struct appctx *appctx, struct peer *p, /* We force new pushed to 1 to force identifier in update message */ new_pushed = 1; - if (!locked) - HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &st->table->lock); + if (locked) + HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &st->table->lock); + + HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &st->table->lock); while (1) { struct stksess *ts; @@ -1633,8 +1635,10 @@ static inline int peer_send_teachmsgs(struct appctx *appctx, struct peer *p, } out: - if (!locked) - HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &st->table->lock); + HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &st->table->lock); + + if (locked) + HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &st->table->lock); return ret; }