From feb7ca0d8ac818761e232f0afbac3cbfd288cd0f Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Tue, 4 Jul 2023 16:05:50 +0100 Subject: [PATCH] Refactors apply_headers in base and manticore When passing in an object to the initializer, the apply_headers would mutate this object and in certain conditions, this would raise "RuntimeError" in JRuby 9.3 and "ConcurrencyError" in JRuby 9.4. This update clones the options object instead. --- lib/elastic/transport/transport/base.rb | 2 +- lib/elastic/transport/transport/http/manticore.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/elastic/transport/transport/base.rb b/lib/elastic/transport/transport/base.rb index 97f691dd..3c11f72f 100644 --- a/lib/elastic/transport/transport/base.rb +++ b/lib/elastic/transport/transport/base.rb @@ -429,7 +429,7 @@ def use_compression? end def apply_headers(client, options) - headers = options[:headers] || {} + headers = options[:headers].clone || {} headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header(client) client.headers[ACCEPT_ENCODING] = GZIP if use_compression? diff --git a/lib/elastic/transport/transport/http/manticore.rb b/lib/elastic/transport/transport/http/manticore.rb index a4e9287f..26aafe38 100644 --- a/lib/elastic/transport/transport/http/manticore.rb +++ b/lib/elastic/transport/transport/http/manticore.rb @@ -162,7 +162,7 @@ def host_unreachable_exceptions private def apply_headers(options) - headers = options[:headers] || options.dig(:transport_options, :headers) || {} + headers = options[:headers].clone || options.dig(:transport_options, :headers).clone || {} headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || find_value(@request_options[:headers], USER_AGENT_REGEX) || user_agent_header headers[ACCEPT_ENCODING] = GZIP if use_compression?