Skip to content

Commit

Permalink
Use actual thread local for Puma::Server.current.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 23, 2024
1 parent c13f747 commit a17539c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

module Puma

# This method was private on Ruby 2.4 but became public on Ruby 2.5+:
Thread.send(:attr_accessor, :puma_server)

# The HTTP Server itself. Serves out a single Rack app.
#
# This class is used by the `Puma::Single` and `Puma::Cluster` classes
Expand Down Expand Up @@ -47,7 +50,6 @@ class Server
attr_accessor :app
attr_accessor :binder

THREAD_LOCAL_KEY = :puma_server

# Create a server for the rack app +app+.
#
Expand Down Expand Up @@ -131,7 +133,7 @@ def inherit_binder(bind)
class << self
# @!attribute [r] current
def current
Thread.current[THREAD_LOCAL_KEY]
Thread.current.puma_server
end

# :nodoc:
Expand Down Expand Up @@ -438,7 +440,7 @@ def handle_check
# Return true if one or more requests were processed.
def process_client(client)
# Advertise this server into the thread
Thread.current[THREAD_LOCAL_KEY] = self
Thread.current.puma_server = self

clean_thread_locals = options[:clean_thread_locals]
close_socket = true
Expand Down

0 comments on commit a17539c

Please sign in to comment.