Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add ability to wakeup and cancel persistent connections

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...
commit 3f529f073122aeca8757860987b043e8647b0923 1 parent 0985a07
Evan Phoenix authored December 08, 2011
0  bin/pumactl 100644 → 100755
File mode changed
7  lib/puma/server.rb
@@ -52,6 +52,7 @@ def initialize(app, events=Events::DEFAULT)
52 52
       @thread_pool = nil
53 53
 
54 54
       @persistent_timeout = PERSISTENT_TIMEOUT
  55
+      @persistent_check, @persistent_wakeup = IO.pipe
55 56
 
56 57
       @proto_env = {
57 58
         "rack.version".freeze => Rack::VERSION,
@@ -219,9 +220,11 @@ def process_client(client)
219 220
                 env = @proto_env.dup
220 221
                 nparsed = 0
221 222
               else
222  
-                unless IO.select([client], nil, nil, @persistent_timeout)
  223
+                unless ret = IO.select([client, @persistent_check], nil, nil, @persistent_timeout)
223 224
                   raise EOFError, "Timed out persistent connection"
224 225
                 end
  226
+
  227
+                return if ret.first.include? @persistent_check
225 228
               end
226 229
             else
227 230
               # Parser is not done, queue up more data to read and continue parsing
@@ -514,12 +517,14 @@ def graceful_shutdown
514 517
     # off the request queue before finally exiting.
515 518
     #
516 519
     def stop(sync=false)
  520
+      @persistent_wakeup.close
517 521
       @notify << STOP_COMMAND
518 522
 
519 523
       @thread.join if @thread && sync
520 524
     end
521 525
 
522 526
     def halt(sync=false)
  527
+      @persistent_wakeup.close
523 528
       @notify << HALT_COMMAND
524 529
 
525 530
       @thread.join if @thread && sync

0 notes on commit 3f529f0

Please sign in to comment.
Something went wrong with that request. Please try again.