]> git.ipfire.org Git - thirdparty/suricata.git/commit
multi-tenant: fix loader dead lock 10442/head
authorVictor Julien <vjulien@oisf.net>
Sun, 11 Feb 2024 08:29:38 +0000 (09:29 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 15 Feb 2024 14:34:05 +0000 (15:34 +0100)
commitd93b21c5240c00657c350f47f0bbc02c29778ad5
tree38d4183d61492402567a3ed90d6e47243ff63a72
parent15bb1d48411abd7aec7b0d685a2ac2dac010cd75
multi-tenant: fix loader dead lock

A dead lock could occur at start up, where a loader thread would
get stuck on it's condition variable, while the main thread was
polling the loaders task results.

The vector to the dead lock is as follows:

main                         loader
DetectEngineMultiTenantSetup
-DetectLoaderSetupLoadTenant
--DetectLoaderQueueTask
---lock loader
---add task
---unlock loader
                        lock loader
                        check/exec tasks
                        unlock loader
---wake up threads
                        lock ctrl mutx
                        cond wait ctrl
                        unlock ctrl
-DetectLoadersSync
--lock loader
--check tasks
--unlock loader

Between the main thread unlocking the loader and waking up the
threads, it is possible that the loader has already moved ahead
but not yet entered its conditional wait. The main thread sends
its condition signal, but since the loader isn't yet waiting on
it the signal is ignored. Then when the loader does enter its
conditional wait, the signal is not sent again.

This patch updates the logic to send signals much more often.
It also makes sure that the signal is sent under lock, as the
API requires.

Bug: #6768.

Co-authored-by: Shivani Bhardwaj <shivani@oisf.net>
src/detect-engine-loader.c
src/detect-engine-loader.h