Conversation
… thread msc_process_logging() evaluates the LOGGING phase and writes the audit log synchronously on the worker's event loop. With SecAuditEngine On, or RelevantOnly under attack traffic, that is per-request file I/O inside the worker. The new opt-in directive posts that work to an nginx thread pool: the transaction is detached from the request pool, processed in the thread, and cleaned up from the completion handler. The libmodsecurity log callback now receives a small holder struct instead of the connection log so its destination can be redirected to the thread pool's log once the request is gone. The early logging path used by interventions stays synchronous. Requires --with-threads and PCRE2; PCRE1 builds refuse the directive because the connector's pcre_malloc swap is process-global.
|
Warning Review limit reachedNext included review available in 14 minutes. View limit detailsLimit details: You’ve used all 4 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



what
modsecurity_log_thread_pool <name> | off(http, server, location; default off). When set, the LOG phase handler postsmsc_process_logging()— phase 5 rule evaluation plus the audit log write — to the named nginxthread_poolinstead of running it on the worker's event loop. The transaction is detached from the request pool, processed in the thread, and released from the task's completion handler on the main thread. If the task cannot be posted (queue full, allocation failure) the connector falls back to the existing synchronous path and logs a warning.r->connection->log, so its destination can be redirected to the thread pool's log once the request is gone. Rule messages emitted during phases 1–4 are unchanged; messages emitted from phase 5 in a thread go to the mainerror_logwithout the client/request suffix.NGX_THREADSandNGX_PCRE2; on other builds the directive is refused at configuration time with an explanatory message. The early logging path used by interventions stays synchronous.error_logtargets only, in-flight tasks at worker shutdown,SecDebugLogwritten from the thread, libmodsecurity must be a release that supports concurrent transactions as used by threaded Apache MPMs).tests/modsecurity-log-thread-pool.t(11 assertions; skips without--with-threadsor with--without-pcre2): blocking still works, phase 5 rules run and the audit log is written from the thread, a location with the directiveoffstill logs synchronously, and the error log proves the thread path was taken (no fallback warning, phase 5 message without request suffix).why
msc_process_logging()writes the audit log synchronously inside the worker. WithSecAuditEngine On, orRelevantOnlyunder attack traffic, that is per-request file I/O on the event loop, blocking every other connection of that worker (Synchronous process of the request destroys performance #227).r, its pool, or its connection. Object lifetimes were walked for every path (sync, offloaded, offload failure, early intervention logging, internal redirect between locations with different settings, request termination, worker shutdown, reload) and the branch runs clean under valgrind with tasks in flight at quit.pcre_malloc/pcre_freearound every libmodsecurity call (see fix: document PCRE1 global state thread-safety hazard and add build w… #380); PCRE2 builds compile those helpers to no-ops.references
sizeof(ctx)cleanup allocation left untouched here), fix: fail closed on swallowed WAF return values #384 (owns thecreate_ctxerror returns left untouched here).Origin: this change comes from a performance review of the connector done with Claude Fable 5.1 (Anthropic). The patch and its test were verified by building the module against nginx master with libmodsecurity 3.0.14 (PCRE2,
--with-threads, with and without--with-debug), without threads, and, with upstream CI's flags (--without-pcre2 --with-http_v2_module --with-http_auth_request_module), against libmodsecurity 3.0.9 (PCRE1), then running the fulltests/modsecurity*.tsuite in each build (16 files; 262 tests where the new test runs, 249 where it skips; all passing) and the new test under valgrind.