diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 2f267190..a42e38a7 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -399,6 +399,7 @@ module Puma # def process_client(client, buffer) begin + clean_thread_locals = @options[:clean_thread_locals] close_socket = true while true @@ -412,6 +413,8 @@ module Puma return unless @queue_requests buffer.reset + ThreadPool.clean_thread_locals if clean_thread_locals + unless client.reset(@status == :run) close_socket = false client.set_timeout @persistent_timeout diff --git a/lib/puma/thread_pool.rb b/lib/puma/thread_pool.rb index 2b44325a..bae166f8 100644 --- a/lib/puma/thread_pool.rb +++ b/lib/puma/thread_pool.rb @@ -45,6 +45,12 @@ module Puma attr_reader :spawned, :trim_requested attr_accessor :clean_thread_locals + def self.clean_thread_locals + Thread.current.keys.each do |key| + Thread.current[key] = nil unless key == :__recursive_key__ + end + end + # How many objects have yet to be processed by the pool? # def backlog @@ -98,9 +104,7 @@ module Puma break unless continue if @clean_thread_locals - Thread.current.keys.each do |key| - Thread.current[key] = nil unless key == :__recursive_key__ - end + ThreadPool.clean_thread_locals end begin