diff --git a/lib/datadog/appsec/processor.rb b/lib/datadog/appsec/processor.rb index ceebbfa8d81..a34bb5a653a 100644 --- a/lib/datadog/appsec/processor.rb +++ b/lib/datadog/appsec/processor.rb @@ -14,20 +14,23 @@ def initialize(processor) @time_ext_ns = 0.0 @timeouts = 0 @events = [] + @run_mutex = Mutex.new end def run(input, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) - start_ns = Core::Utils::Time.get_time(:nanosecond) + @run_mutex.synchronize do + start_ns = Core::Utils::Time.get_time(:nanosecond) - # TODO: remove multiple assignment - _code, res = _ = @context.run(input, timeout) - # @type var res: WAF::Result + # TODO: remove multiple assignment + _code, res = _ = @context.run(input, timeout) + # @type var res: WAF::Result - stop_ns = Core::Utils::Time.get_time(:nanosecond) + stop_ns = Core::Utils::Time.get_time(:nanosecond) - @time_ns += res.total_runtime - @time_ext_ns += (stop_ns - start_ns) - @timeouts += 1 if res.timeout + @time_ns += res.total_runtime + @time_ext_ns += (stop_ns - start_ns) + @timeouts += 1 if res.timeout + end res end