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