From ce47f43f159feb3438a17059a18a76b33ca1f3d2 Mon Sep 17 00:00:00 2001 From: Ry Biesemeyer Date: Thu, 19 Dec 2024 15:48:05 -0800 Subject: [PATCH] Avoid lock when ecs_compatibility is explicitly specified (#16786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because a `break` escapes a `begin`...`end` block, we must not use a `break` in order to ensure that the explicitly set value gets memoized to avoid lock contention. > ~~~ ruby > def fake_sync(&block) > puts "FAKE_SYNC:enter" > val = yield > puts "FAKE_SYNC:return(#{val})" > return val > ensure > puts "FAKE_SYNC:ensure" > end > > fake_sync do > @ivar = begin > puts("BE:begin") > break :break > > val = :ret > puts("BE:return(#{val})") > val > ensure > puts("BE:ensure") > end > end > ~~~ Note: no `FAKE_SYNC:return`: > ~~~ > ╭─{ rye@perhaps:~/src/elastic/logstash (main ✔) } > ╰─● ruby break-esc.rb > FAKE_SYNC:enter > BE:begin > BE:ensure > FAKE_SYNC:ensure > [success] > ~~~ (cherry picked from commit 01c8e8bb550f31ab89f68f6523431138d722dd50) --- .../lib/logstash/plugins/ecs_compatibility_support.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/logstash-core/lib/logstash/plugins/ecs_compatibility_support.rb b/logstash-core/lib/logstash/plugins/ecs_compatibility_support.rb index 21398ba776a..17602a6b177 100644 --- a/logstash-core/lib/logstash/plugins/ecs_compatibility_support.rb +++ b/logstash-core/lib/logstash/plugins/ecs_compatibility_support.rb @@ -9,10 +9,11 @@ def self.included(base) def ecs_compatibility @_ecs_compatibility || LogStash::Util.synchronize(self) do - @_ecs_compatibility ||= begin - # use config_init-set value if present - break @ecs_compatibility unless @ecs_compatibility.nil? + # use config_init-set value if present + @_ecs_compatibility ||= @ecs_compatibility + # load default from settings + @_ecs_compatibility ||= begin pipeline = execution_context.pipeline pipeline_settings = pipeline && pipeline.settings pipeline_settings ||= LogStash::SETTINGS