-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Review and document multi-threading support and limitations #3215
Comments
@airween: I think #3138 could be closed with a reference to this. |
Created PR #3216 to try to correct this. |
- This is controlled by specifying the 'test_multithreaded' argument when running `unit_test`. - The goal is to detect if the operator/transformation fails in this context. - In this mode, the test will be executed 5'000 times in 50 threads concurrently. - Allocation & initialization of the operator/transformation is performed once in the main thread, while the evaluation is executed in the threads. - This is consistent with the library's support for multithreading, where initialization and loading of rules is expected to run once. See issue owasp-modsecurity#3215.
- This is controlled by specifying the 'test_multithreaded' argument when running `unit_test`. - The goal is to detect if the operator/transformation fails in this context. - In this mode, the test will be executed 5'000 times in 50 threads concurrently. - Allocation & initialization of the operator/transformation is performed once in the main thread, while the evaluation is executed in the threads. - This is consistent with the library's support for multithreading, where initialization and loading of rules is expected to run once. See issue owasp-modsecurity#3215.
The need for this optional lock was reviewed and confirmed not to be necessary. PR #3227 was submitted to remove it. |
Created PR #3228 to address this. |
- This is controlled by specifying the 'mtstress' argument when running `unit_test`. - The goal is to detect if the operator/transformation fails in this context. - In this mode, the test will be executed 5'000 times in 50 threads concurrently. - Allocation & initialization of the operator/transformation is performed once in the main thread, while the evaluation is executed in the threads. - This is consistent with the library's support for multithreading, where initialization and loading of rules is expected to run once. See issue owasp-modsecurity#3215.
The goal of this issue is to collect and centralize information about multi-threading support of the current version of modSecurity , as the topic has come up in a number of issues and there are documented guidelines about usage in this context.
Multi-threading support
The library is expected to work in multi-threaded scenarios, as stated in #1726. This means that any issues should be related to incorrect usage or bugs in the current implementation.
"The modSecurity life cycle is divided into different stages. The stage that the rules are loaded is not threading safe by design. (...) Once the rules are loaded multiple requests can share the same
RulesSet
object, leading to parallelism while addressing different requests in different processes or threads." (Source: #2536, here)Notes
Operator
&Action
(includingTransformation
) objects are created in the first stage, when rules are loaded and parsed, so their initialization is not synchronized. If their evaluation updates internal state, this needs to be protected to prevent issues in multithreaded contexts.Examples
The repository currently includes an example of usage of the library in a multi-threaded context, see reading_logs_via_rule_message in the
examples
directory.Potential issues/limitations
F_SETLKW
fcntl
to lock the shared files.F_SETLKW
fcntl
in commit 3d20304 due to an unlocking issue under heavy load using nginx, where an acquired lock would not be released when the process was killed.EOWNERDEAD
return value, which allows it to recover the mutex and make it 'consistent' (see PTHREAD_MUTEX_ROBUST).Reviewed/addressed issues
MODSEC_MUTEX_ON_PM
define &--enable-mutex-on-pm
configure flagacmp
trees.string.h
'sascTime
usesstd::ctime
, which is not safe in multi-threaded contextsascTime
is used byTransaction::toJSON
, which is used to log transactions.Non-reentrant POSIX functions should be replaced with their reentrant versions cpp:S1912
Misc
unit_test
program has support to run the operator/transformation tests in a multi-threaded context (launching 50 threads and running each test 5000 times).The text was updated successfully, but these errors were encountered: