]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: peers: drop then re-acquire the wrlock in peer_send_teachmsgs()
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Jul 2023 14:03:27 +0000 (14:03 +0000)
committerWilly Tarreau <w@1wt.eu>
Fri, 11 Aug 2023 17:03:35 +0000 (19:03 +0200)
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

index c7c28b1ee0419e93ff77af10dc50eaa8678ab464..23f6e5d12b86584dc7355c58d581a0e19206e01c 100644 (file)
@@ -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;
 }