Skip to content

Commit ae6e647

Browse files
explain 'race-condition' as discussed in CR
Fixes #125
1 parent cff8035 commit ae6e647

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/logstash/filters/grok/timeout_enforcer.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def start_thread_groking(thread)
7272
@threads_to_start_time.put(thread, java.lang.System.nanoTime)
7373
end
7474

75+
# Returns falsy in case there was no Grok execution in progress for the thread
7576
def stop_thread_groking(thread)
7677
@threads_to_start_time.remove(thread)
7778
end
@@ -82,8 +83,13 @@ def cancel_timed_out!
8283
start_time = entry.get_value
8384
if start_time < now && now - start_time > @timeout_nanos
8485
thread = entry.get_key
85-
# Ensure that we never attempt to cancel this thread twice in the event
86-
# of weird races
86+
# Ensure that we never attempt to cancel this thread unless a Grok execution is in progress
87+
# Theoretically there is a race condition here in case the entry's grok action changed
88+
# between evaluating the above condition on the start_time and calling stop_thread_groking
89+
# Practically this is impossible, since it would require a whole loop of writing to an
90+
# output, pulling new input events and starting a new Grok execution in worker thread
91+
# in between the above `if start_time < now && now - start_time > @timeout_nanos` and
92+
# the call to `stop_thread_groking`.
8793
if stop_thread_groking(thread)
8894
@cancel_mutex.lock
8995
begin

0 commit comments

Comments
 (0)