From 9ce3b112b924a597072db6c7cda8d7deff808533 Mon Sep 17 00:00:00 2001 From: Haruki Hasegawa Date: Thu, 26 Sep 2024 19:26:38 +0900 Subject: [PATCH] Use isolated connection configurations in the output plugin Modify to use isolated connection configurations for each plugin instance. The previous implementation had an issue where incorrect connections were used due to ActiveRecord's connection pooling mechanism when the output plugin was used multiple times. Signed-off-by: Haruki Hasegawa --- lib/fluent/plugin/out_sql.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/out_sql.rb b/lib/fluent/plugin/out_sql.rb index d55f9fe..23dfa79 100644 --- a/lib/fluent/plugin/out_sql.rb +++ b/lib/fluent/plugin/out_sql.rb @@ -206,7 +206,7 @@ def start end SQLOutput.const_set("BaseModel_#{rand(1 << 31)}", @base_model) - ActiveRecord::Base.establish_connection(config) + @base_model.establish_connection(config) # ignore tables if TableElement#init failed @tables.reject! do |te| @@ -224,7 +224,7 @@ def formatted_to_msgpack_binary end def write(chunk) - ActiveRecord::Base.connection_pool.with_connection do + @base_model.connection_pool.with_connection do @tables.each { |table| tag = format_tag(chunk.metadata.tag)