From e302d1bc01e1a2ba3af2b4fe9aee7c226bc87b00 Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 16 Nov 2026 17:14:56 +0000 Subject: [PATCH] =?UTF-8?q?balance:=20round-robin-Turn=20f=C3=BCr=20parall?= =?UTF-8?q?ele=20Anfragen=20atomar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zwei gleichzeitig startende Anfragen lasen denselben rr_turn und wählten dasselbe Ziel; die zweite wartete dann am Model-Gate des ersten, statt auf die nächste Box zu gehen. Der Turn wird jetzt unter einem Mutex gezogen. --- src/junction.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/junction.c b/src/junction.c index 1e0f679..70a7e3e 100644 --- a/src/junction.c +++ b/src/junction.c @@ -2087,6 +2087,8 @@ static double ep_score(const j_endpoint *ep) /* Order the rule's targets according to the configured balance mode. "first" * keeps rule order, which is what a failover chain wants; the others sort. */ +static pthread_mutex_t g_rr_mu = PTHREAD_MUTEX_INITIALIZER; + static void balance_order(const j_rule *r, int *order, int n) { static unsigned long rr_turn; @@ -2111,7 +2113,12 @@ static void balance_order(const j_rule *r, int *order, int n) slots[ns++] = i; } if (!ns) return; - int shift = (int)(rr_turn++ % (unsigned long)ns); + /* Concurrent requests must get different turns; otherwise two requests + * starting together both pick the same first target and queue there. */ + pthread_mutex_lock(&g_rr_mu); + unsigned long turn = rr_turn++; + pthread_mutex_unlock(&g_rr_mu); + int shift = (int)(turn % (unsigned long)ns); int seen = 0; for (int s2 = 0; s2 < ns && seen < n; s2++) { int t = slots[(s2 + shift) % ns];