Skip to content

Commit

Permalink
stop http server safely
Browse files Browse the repository at this point in the history
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
  • Loading branch information
Watson1978 committed Aug 28, 2024
1 parent 0d63b5a commit b80b288
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/fluent/plugin_helper/http_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def initialize(addr:, port:, logger:, default_app: nil, tls_context: nil)
@uri = URI("#{scheme}://#{@addr}:#{@port}").to_s
@router = Router.new(default_app)
@server_task = nil
@server_task_queue = Thread::Queue.new

Console.logger = Fluent::Log::ConsoleAdapter.wrap(@logger)

opts = if tls_context
Expand Down Expand Up @@ -67,17 +69,17 @@ def start(notify = nil)
if notify
notify.push(:ready)
end

@server_task_queue.pop
@server_task.stop
end

@logger.debug('Finished HTTP server')
end

def stop
@logger.debug('closing HTTP server')

if @server_task
@server_task.stop
end
@server_task_queue.push(:stop)
end

HttpServer::Methods::ALL.map { |e| e.downcase.to_sym }.each do |name|
Expand Down

0 comments on commit b80b288

Please sign in to comment.