diff --git a/lib/fluent/plugin/out_http.rb b/lib/fluent/plugin/out_http.rb index 09ab90858d..6fb972c3d3 100644 --- a/lib/fluent/plugin/out_http.rb +++ b/lib/fluent/plugin/out_http.rb @@ -37,7 +37,7 @@ class HTTPOutput < Output class RetryableResponse < StandardError; end - CacheEntry = Struct.new(:uri, :conn) + ConnectionCache = Struct.new(:uri, :conn) helpers :formatter @@ -111,22 +111,21 @@ def initialize @proxy_uri = nil @formatter = nil - @cache = [] - @cache_id_mutex = Mutex.new + @connection_cache = [] + @connection_cache_id_mutex = Mutex.new end def close super - # Close all open connections - @cache.each {|entry| entry.conn.finish if entry.conn&.started? } + @connection_cache.each {|entry| entry.conn.finish if entry.conn&.started? } end def configure(conf) super - @cache = Array.new(actual_flush_thread_count, CacheEntry.new("", nil)) if @reuse_connections - @cache_id = 0 + @connection_cache = Array.new(actual_flush_thread_count, ConnectionCache.new("", nil)) if @reuse_connections + @connection_cache_id = 0 if @retryable_response_codes.nil? log.warn('Status code 503 is going to be removed from default `retryable_response_codes` from fluentd v2. Please add it by yourself if you wish') @@ -322,23 +321,23 @@ def create_request(chunk, uri) def make_request_cached(uri, req) id = Thread.current.thread_variable_get(plugin_id) if id.nil? - @cache_id_mutex.synchronize { - id = @cache_id - @cache_id += 1 + @connection_cache_id_mutex.synchronize { + id = @connection_cache_id + @connection_cache_id += 1 } Thread.current.thread_variable_set(plugin_id, id) end uri_str = uri.to_s - if @cache[id].uri != uri_str - @cache[id].conn.finish if @cache[id].conn&.started? + if @connection_cache[id].uri != uri_str + @connection_cache[id].conn.finish if @connection_cache[id].conn&.started? http = if @proxy_uri Net::HTTP.start(uri.host, uri.port, @proxy_uri.host, @proxy_uri.port, @proxy_uri.user, @proxy_uri.password, @http_opt) else Net::HTTP.start(uri.host, uri.port, @http_opt) end - @cache[id] = CacheEntry.new(uri_str, http) + @connection_cache[id] = ConnectionCache.new(uri_str, http) end - @cache[id].conn.request(req) + @connection_cache[id].conn.request(req) end def make_request(uri, req, &block)