Skip to content

Commit

Permalink
http_server: Stop http server safely
Browse files Browse the repository at this point in the history
Signed-off-by: Shizuo Fujita <[email protected]>
  • Loading branch information
Watson1978 committed Oct 2, 2024
1 parent af8aa13 commit c9aafc8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/fluent/plugin_helper/http_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,23 @@ 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')
end

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

Expand All @@ -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
Expand Down

0 comments on commit c9aafc8

Please sign in to comment.