From ea5e4c67ec23912aa30372dc8154ba41db210d39 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Wed, 28 Aug 2024 18:07:30 +0900 Subject: [PATCH] http_server: Stop http server safely Signed-off-by: Shizuo Fujita --- lib/fluent/plugin_helper/http_server/server.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin_helper/http_server/server.rb b/lib/fluent/plugin_helper/http_server/server.rb index a7b561e6be..50df177e83 100644 --- a/lib/fluent/plugin_helper/http_server/server.rb +++ b/lib/fluent/plugin_helper/http_server/server.rb @@ -67,6 +67,12 @@ def start(notify = nil) if notify notify.push(:ready) end + + if async_v2? + @server_task_queue = ::Thread::Queue.new + @server_task_queue.pop + @server_task&.stop + end end @logger.debug('Finished HTTP server') @@ -74,9 +80,10 @@ def start(notify = nil) def stop @logger.debug('closing HTTP server') - - if @server_task - @server_task.stop + if async_v2? + @server_task_queue&.push(:stop) + else + @server_task&.stop end end @@ -93,6 +100,10 @@ def stop @router.mount(name, path, app || block) end end + + private def async_v2? + Gem::Version.new(Async::VERSION) >= Gem::Version.new('2.0') + end end end end