Skip to content

Commit

Permalink
Add ability to wakeup and cancel persistent connections
Browse files Browse the repository at this point in the history
Without this, the graceful stop code has to wait for the persistent
timeout to expire even though there is actually no work going on.
  • Loading branch information
evanphx committed Dec 8, 2011
1 parent 0985a07 commit 3f529f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Empty file modified bin/pumactl 100644 → 100755
Empty file.
7 changes: 6 additions & 1 deletion lib/puma/server.rb
Expand Up @@ -52,6 +52,7 @@ def initialize(app, events=Events::DEFAULT)
@thread_pool = nil

@persistent_timeout = PERSISTENT_TIMEOUT
@persistent_check, @persistent_wakeup = IO.pipe

@proto_env = {
"rack.version".freeze => Rack::VERSION,
Expand Down Expand Up @@ -219,9 +220,11 @@ def process_client(client)
env = @proto_env.dup
nparsed = 0
else
unless IO.select([client], nil, nil, @persistent_timeout)
unless ret = IO.select([client, @persistent_check], nil, nil, @persistent_timeout)
raise EOFError, "Timed out persistent connection"
end

return if ret.first.include? @persistent_check
end
else
# Parser is not done, queue up more data to read and continue parsing
Expand Down Expand Up @@ -514,12 +517,14 @@ def graceful_shutdown
# off the request queue before finally exiting.
#
def stop(sync=false)
@persistent_wakeup.close
@notify << STOP_COMMAND

@thread.join if @thread && sync
end

def halt(sync=false)
@persistent_wakeup.close
@notify << HALT_COMMAND

@thread.join if @thread && sync
Expand Down

0 comments on commit 3f529f0

Please sign in to comment.