Skip to content

Commit

Permalink
Protect Processor::Context#run with a mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Apr 11, 2023
1 parent 650ba0c commit d26a468
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/datadog/appsec/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d26a468

Please sign in to comment.