summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurelien DARRAGON <adarragon@haproxy.com>2023-05-11 17:46:42 +0200
committerChristopher Faulet <cfaulet@haproxy.com>2023-05-12 09:45:30 +0200
commit4cc2714ae2b40b84b1ee361dceab71a3acd8fb4a (patch)
treef6394e9925844b8a3bdedc55a2ef43cb33818db8
parent2a29571c11a5c4d12192f355d1475b0ee9f1142d (diff)
downloadhaproxy-4cc2714ae2b40b84b1ee361dceab71a3acd8fb4a.tar.gz
EXAMPLES: fix race condition in lua mailers script
Christopher reported a rare race condition involving 'healthcheckmail.vtc' The regtest would randomly FAIL with this kind of error: ** S1 === expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server b... **** S1 EXPECT MATCH ~ "[^:\[ ]\[581669\]: Health check for server be1/srv1 failed.+check duration: [[:digit:]]+ms.+status: 0/1 DOWN." ** S1 === recv info **** S1 syslog|<25>May 11 15:38:46 haproxy[581669]: Server be1/srv1 is DOWN. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue. **** S1 syslog|<24>May 11 15:38:46 haproxy[581669]: backend be1 has no server available! It turns out that this it due to the recent commit 7963fb5 ("REGTESTS: use lua mailer script for mailers tests") in which we tell the regtest to use the new lua mailers instead of the legacy mailers API. However, in the lua mailers script, due to the event subscriptions being performed from a lua task, it is possible that the subscription may be delayed during startup. Indeed lua tasks relie on the scheduler which runs tasks with no ordering guarantees. Thus early tasks, including server checks which are used in the regtest are competing during startup. As such, we may end up with some events that are generated right before the lua mailers script starts subscribing to events (because the lua task is scheduled but started yet), resulting in events loss from lua point of view. To fix this and to make lua mailers more reliable during startup, we now perform the events subscription from an init function instead of an asynchronous task. (The init function is called synchronously during haproxy post_init, and exclusively runs before the scheduler starts) This should be enough to prevent healthcheckmail.vtc from randomly failing
-rw-r--r--examples/lua/mailers.lua6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/lua/mailers.lua b/examples/lua/mailers.lua
index 8c12f7826..c7ffa0376 100644
--- a/examples/lua/mailers.lua
+++ b/examples/lua/mailers.lua
@@ -362,9 +362,9 @@ end
-- disable legacy email-alerts since email-alerts will be sent from lua directly
core.disable_legacy_mailers()
--- event subscription are purposely performed in a task to prevent email
--- alerts from being generated too early (when process is starting up)
-core.register_task(function()
+-- event subscriptions are purposely performed in an init function to prevent
+-- email alerts from being generated too early (when process is starting up)
+core.register_init(function()
-- do nothing if not on primary thread
-- this prevents emails from being sent multiple times when