]> git.ipfire.org Git - thirdparty/suricata.git/commit
multi-tenant: fix loader dead lock 10383/head
authorVictor Julien <vjulien@oisf.net>
Sun, 11 Feb 2024 08:29:38 +0000 (09:29 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 12 Feb 2024 11:45:31 +0000 (12:45 +0100)
commit7956fa52423f80858643b25080efba2f64d78512
tree4a9f95c9d98d889f8f298e1b1e7825ed00e4d230
parent9fe00ff71077caf5d13ac442ef2d729a88b00c49
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: #6766.
src/detect-engine-loader.c
src/detect-engine-loader.h