From: Willy Tarreau Date: Fri, 28 Jul 2023 14:03:27 +0000 (+0000) Subject: MEDIUM: peers: drop then re-acquire the wrlock in peer_send_teachmsgs() X-Git-Tag: v2.9-dev3~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4f8286e45618fa1017c79e32950487f1d1ad4d4;p=thirdparty%2Fhaproxy.git 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(). --- diff --git a/src/peers.c b/src/peers.c index c7c28b1ee0..23f6e5d12b 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; }