From c7c35d0b28089f920e0516896965510818641f59 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Mon, 29 Jul 2024 16:14:54 +0900 Subject: [PATCH] Apply PR#468 patch only for 0.12.x. With https://github.com/fluent/fluent-plugin-kafka/pull/468, rdkafka 0.12.0 specific patch (Rdkafka::Producer::Client) was introduced [1], but rdkafka's internal change was reverted [2] (removed Rdkafka::Producer::Client) later in 0.13.x. [1] https://github.com/karafka/rdkafka-ruby/pull/172 [2] https://github.com/karafka/rdkafka-ruby/pull/211 So this monkey patch should be effective only between 0.12.0 and 0.12.1 (only 2 versions were shipped in 0.12.x). For 0.13.x or later, it seems harmful. Signed-off-by: Kentaro Hayashi --- lib/fluent/plugin/out_rdkafka2.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/out_rdkafka2.rb b/lib/fluent/plugin/out_rdkafka2.rb index 1703f78..183eb44 100644 --- a/lib/fluent/plugin/out_rdkafka2.rb +++ b/lib/fluent/plugin/out_rdkafka2.rb @@ -30,7 +30,10 @@ class Rdkafka::Producer def close(timeout = nil) rdkafka_version = Rdkafka::VERSION || '0.0.0' # Rdkafka version >= 0.12.0 changed its internals - if Gem::Version::create(rdkafka_version) >= Gem::Version.create('0.12.0') + # but reverted in >= 0.13.0 + gem_version = Gem::Version::create(rdkafka_version) + if gem_version >= Gem::Version.create('0.12.0') and + gem_version <= Gem::Version.create('0.12.1') ObjectSpace.undefine_finalizer(self) return @client.close(timeout)