puma 3.9.1 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puma might be problematic. Click here for more details.

Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +232 -0
  3. data/README.md +162 -224
  4. data/docs/architecture.md +37 -0
  5. data/{DEPLOYMENT.md → docs/deployment.md} +24 -4
  6. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  7. data/docs/images/puma-connection-flow.png +0 -0
  8. data/docs/images/puma-general-arch.png +0 -0
  9. data/docs/plugins.md +38 -0
  10. data/docs/restart.md +41 -0
  11. data/docs/signals.md +56 -3
  12. data/docs/systemd.md +130 -37
  13. data/docs/tcp_mode.md +96 -0
  14. data/ext/puma_http11/PumaHttp11Service.java +2 -0
  15. data/ext/puma_http11/extconf.rb +13 -0
  16. data/ext/puma_http11/http11_parser.c +115 -140
  17. data/ext/puma_http11/http11_parser.java.rl +21 -37
  18. data/ext/puma_http11/http11_parser.rl +9 -9
  19. data/ext/puma_http11/http11_parser_common.rl +3 -3
  20. data/ext/puma_http11/mini_ssl.c +104 -8
  21. data/ext/puma_http11/org/jruby/puma/Http11.java +106 -114
  22. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +90 -108
  23. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  24. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +21 -4
  25. data/ext/puma_http11/puma_http11.c +2 -0
  26. data/lib/puma.rb +16 -0
  27. data/lib/puma/accept_nonblock.rb +7 -1
  28. data/lib/puma/app/status.rb +40 -26
  29. data/lib/puma/binder.rb +57 -74
  30. data/lib/puma/cli.rb +26 -7
  31. data/lib/puma/client.rb +243 -190
  32. data/lib/puma/cluster.rb +78 -34
  33. data/lib/puma/commonlogger.rb +2 -0
  34. data/lib/puma/configuration.rb +24 -16
  35. data/lib/puma/const.rb +36 -18
  36. data/lib/puma/control_cli.rb +46 -19
  37. data/lib/puma/detect.rb +2 -0
  38. data/lib/puma/dsl.rb +329 -68
  39. data/lib/puma/events.rb +6 -1
  40. data/lib/puma/io_buffer.rb +3 -6
  41. data/lib/puma/jruby_restart.rb +2 -1
  42. data/lib/puma/launcher.rb +120 -58
  43. data/lib/puma/minissl.rb +69 -27
  44. data/lib/puma/minissl/context_builder.rb +76 -0
  45. data/lib/puma/null_io.rb +2 -0
  46. data/lib/puma/plugin.rb +7 -2
  47. data/lib/puma/plugin/tmp_restart.rb +2 -1
  48. data/lib/puma/rack/builder.rb +4 -1
  49. data/lib/puma/rack/urlmap.rb +2 -0
  50. data/lib/puma/rack_default.rb +2 -0
  51. data/lib/puma/reactor.rb +224 -34
  52. data/lib/puma/runner.rb +25 -4
  53. data/lib/puma/server.rb +148 -62
  54. data/lib/puma/single.rb +16 -5
  55. data/lib/puma/state_file.rb +2 -0
  56. data/lib/puma/tcp_logger.rb +2 -0
  57. data/lib/puma/thread_pool.rb +61 -38
  58. data/lib/puma/util.rb +2 -6
  59. data/lib/rack/handler/puma.rb +10 -4
  60. data/tools/docker/Dockerfile +16 -0
  61. data/tools/jungle/README.md +12 -2
  62. data/tools/jungle/init.d/README.md +2 -0
  63. data/tools/jungle/init.d/puma +8 -8
  64. data/tools/jungle/init.d/run-puma +1 -1
  65. data/tools/jungle/rc.d/README.md +74 -0
  66. data/tools/jungle/rc.d/puma +61 -0
  67. data/tools/jungle/rc.d/puma.conf +10 -0
  68. data/tools/trickletest.rb +1 -2
  69. metadata +29 -56
  70. data/.github/issue_template.md +0 -20
  71. data/Gemfile +0 -14
  72. data/Manifest.txt +0 -78
  73. data/Rakefile +0 -165
  74. data/Release.md +0 -9
  75. data/gemfiles/2.1-Gemfile +0 -12
  76. data/lib/puma/compat.rb +0 -14
  77. data/lib/puma/convenient.rb +0 -23
  78. data/lib/puma/daemon_ext.rb +0 -31
  79. data/lib/puma/delegation.rb +0 -11
  80. data/lib/puma/java_io_buffer.rb +0 -45
  81. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
  82. data/puma.gemspec +0 -20
@@ -0,0 +1,76 @@
1
+ module Puma
2
+ module MiniSSL
3
+ class ContextBuilder
4
+ def initialize(params, events)
5
+ require 'puma/minissl'
6
+ MiniSSL.check
7
+
8
+ @params = params
9
+ @events = events
10
+ end
11
+
12
+ def context
13
+ ctx = MiniSSL::Context.new
14
+
15
+ if defined?(JRUBY_VERSION)
16
+ unless params['keystore']
17
+ events.error "Please specify the Java keystore via 'keystore='"
18
+ end
19
+
20
+ ctx.keystore = params['keystore']
21
+
22
+ unless params['keystore-pass']
23
+ events.error "Please specify the Java keystore password via 'keystore-pass='"
24
+ end
25
+
26
+ ctx.keystore_pass = params['keystore-pass']
27
+ ctx.ssl_cipher_list = params['ssl_cipher_list'] if params['ssl_cipher_list']
28
+ else
29
+ unless params['key']
30
+ events.error "Please specify the SSL key via 'key='"
31
+ end
32
+
33
+ ctx.key = params['key']
34
+
35
+ unless params['cert']
36
+ events.error "Please specify the SSL cert via 'cert='"
37
+ end
38
+
39
+ ctx.cert = params['cert']
40
+
41
+ if ['peer', 'force_peer'].include?(params['verify_mode'])
42
+ unless params['ca']
43
+ events.error "Please specify the SSL ca via 'ca='"
44
+ end
45
+ end
46
+
47
+ ctx.ca = params['ca'] if params['ca']
48
+ ctx.ssl_cipher_filter = params['ssl_cipher_filter'] if params['ssl_cipher_filter']
49
+ end
50
+
51
+ ctx.no_tlsv1 = true if params['no_tlsv1'] == 'true'
52
+ ctx.no_tlsv1_1 = true if params['no_tlsv1_1'] == 'true'
53
+
54
+ if params['verify_mode']
55
+ ctx.verify_mode = case params['verify_mode']
56
+ when "peer"
57
+ MiniSSL::VERIFY_PEER
58
+ when "force_peer"
59
+ MiniSSL::VERIFY_PEER | MiniSSL::VERIFY_FAIL_IF_NO_PEER_CERT
60
+ when "none"
61
+ MiniSSL::VERIFY_NONE
62
+ else
63
+ events.error "Please specify a valid verify_mode="
64
+ MiniSSL::VERIFY_NONE
65
+ end
66
+ end
67
+
68
+ ctx
69
+ end
70
+
71
+ private
72
+
73
+ attr_reader :params, :events
74
+ end
75
+ end
76
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Puma
2
4
  # Provides an IO-like object that always appears to contain no data.
3
5
  # Used as the value for rack.input when the request has no body.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Puma
2
4
  class UnknownPlugin < RuntimeError; end
3
5
 
@@ -60,8 +62,11 @@ module Puma
60
62
  end
61
63
 
62
64
  def fire_background
63
- @background.each do |b|
64
- Thread.new(&b)
65
+ @background.each_with_index do |b, i|
66
+ Thread.new do
67
+ Puma.set_thread_name "plugin background #{i}"
68
+ b.call
69
+ end
65
70
  end
66
71
  end
67
72
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puma/plugin'
2
4
 
3
5
  Puma::Plugin.create do
@@ -32,4 +34,3 @@ Puma::Plugin.create do
32
34
  end
33
35
  end
34
36
  end
35
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Puma
2
4
  end
3
5
 
@@ -110,7 +112,8 @@ module Puma::Rack
110
112
 
111
113
  has_options = false
112
114
  server.valid_options.each do |name, description|
113
- next if name.to_s.match(/^(Host|Port)[^a-zA-Z]/) # ignore handler's host and port options, we do our own.
115
+ next if name.to_s =~ /^(Host|Port)[^a-zA-Z]/ # ignore handler's host and port options, we do our own.
116
+
114
117
  info << " -O %-21s %s" % [name, description]
115
118
  has_options = true
116
119
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Puma::Rack
2
4
  # Rack::URLMap takes a hash mapping urls or paths to apps, and
3
5
  # dispatches accordingly. Support for HTTP/1.1 host names exists if
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rack/handler/puma'
2
4
 
3
5
  module Rack::Handler
@@ -1,57 +1,201 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puma/util'
2
4
  require 'puma/minissl'
3
5
 
6
+ require 'nio'
7
+
4
8
  module Puma
9
+ # Internal Docs, Not a public interface.
10
+ #
11
+ # The Reactor object is responsible for ensuring that a request has been
12
+ # completely received before it starts to be processed. This may be known as read buffering.
13
+ # If read buffering is not done, and no other read buffering is performed (such as by an application server
14
+ # such as nginx) then the application would be subject to a slow client attack.
15
+ #
16
+ # Each Puma "worker" process has its own Reactor. For example if you start puma with `$ puma -w 5` then
17
+ # it will have 5 workers and each worker will have it's own reactor.
18
+ #
19
+ # For a graphical representation of how the reactor works see [architecture.md](https://github.com/puma/puma/blob/master/docs/architecture.md#connection-pipeline).
20
+ #
21
+ # ## Reactor Flow
22
+ #
23
+ # A connection comes into a `Puma::Server` instance, it is then passed to a `Puma::Reactor` instance,
24
+ # which stores it in an array and waits for any of the connections to be ready for reading.
25
+ #
26
+ # The waiting/wake up is performed with nio4r, which will use the appropriate backend (libev, Java NIO or
27
+ # just plain IO#select). The call to `NIO::Selector#select` will "wake up" and
28
+ # return the references to any objects that caused it to "wake". The reactor
29
+ # then loops through each of these request objects, and sees if they're complete. If they
30
+ # have a full header and body then the reactor passes the request to a thread pool.
31
+ # Once in a thread pool, a "worker thread" can run the the application's Ruby code against the request.
32
+ #
33
+ # If the request is not complete, then it stays in the array, and the next time any
34
+ # data is written to that socket reference, then the loop is woken up and it is checked for completeness again.
35
+ #
36
+ # A detailed example is given in the docs for `run_internal` which is where the bulk
37
+ # of this logic lives.
5
38
  class Reactor
6
39
  DefaultSleepFor = 5
7
40
 
41
+ # Creates an instance of Puma::Reactor
42
+ #
43
+ # The `server` argument is an instance of `Puma::Server`
44
+ # that is used to write a response for "low level errors"
45
+ # when there is an exception inside of the reactor.
46
+ #
47
+ # The `app_pool` is an instance of `Puma::ThreadPool`.
48
+ # Once a request is fully formed (header and body are received)
49
+ # it will be passed to the `app_pool`.
8
50
  def initialize(server, app_pool)
9
51
  @server = server
10
52
  @events = server.events
11
53
  @app_pool = app_pool
12
54
 
55
+ @selector = NIO::Selector.new
56
+
13
57
  @mutex = Mutex.new
58
+
59
+ # Read / Write pipes to wake up internal while loop
14
60
  @ready, @trigger = Puma::Util.pipe
15
61
  @input = []
16
62
  @sleep_for = DefaultSleepFor
17
63
  @timeouts = []
18
64
 
19
- @sockets = [@ready]
65
+ mon = @selector.register(@ready, :r)
66
+ mon.value = @ready
67
+
68
+ @monitors = [mon]
20
69
  end
21
70
 
22
71
  private
23
72
 
73
+ # Until a request is added via the `add` method this method will internally
74
+ # loop, waiting on the `sockets` array objects. The only object in this
75
+ # array at first is the `@ready` IO object, which is the read end of a pipe
76
+ # connected to `@trigger` object. When `@trigger` is written to, then the loop
77
+ # will break on `NIO::Selector#select` and return an array.
78
+ #
79
+ # ## When a request is added:
80
+ #
81
+ # When the `add` method is called, an instance of `Puma::Client` is added to the `@input` array.
82
+ # Next the `@ready` pipe is "woken" by writing a string of `"*"` to `@trigger`.
83
+ #
84
+ # When that happens, the internal loop stops blocking at `NIO::Selector#select` and returns a reference
85
+ # to whatever "woke" it up. On the very first loop, the only thing in `sockets` is `@ready`.
86
+ # When `@trigger` is written-to, the loop "wakes" and the `ready`
87
+ # variable returns an array of arrays that looks like `[[#<IO:fd 10>], [], []]` where the
88
+ # first IO object is the `@ready` object. This first array `[#<IO:fd 10>]`
89
+ # is saved as a `reads` variable.
90
+ #
91
+ # The `reads` variable is iterated through. In the case that the object
92
+ # is the same as the `@ready` input pipe, then we know that there was a `trigger` event.
93
+ #
94
+ # If there was a trigger event, then one byte of `@ready` is read into memory. In the case of the first request,
95
+ # the reactor sees that it's a `"*"` value and the reactor adds the contents of `@input` into the `sockets` array.
96
+ # The while then loop continues to iterate again, but now the `sockets` array contains a `Puma::Client` instance in addition
97
+ # to the `@ready` IO object. For example: `[#<IO:fd 10>, #<Puma::Client:0x3fdc1103bee8 @ready=false>]`.
98
+ #
99
+ # Since the `Puma::Client` in this example has data that has not been read yet,
100
+ # the `NIO::Selector#select` is immediately able to "wake" and read from the `Puma::Client`. At this point the
101
+ # `ready` output looks like this: `[[#<Puma::Client:0x3fdc1103bee8 @ready=false>], [], []]`.
102
+ #
103
+ # Each element in the first entry is iterated over. The `Puma::Client` object is not
104
+ # the `@ready` pipe, so the reactor checks to see if it has the full header and body with
105
+ # the `Puma::Client#try_to_finish` method. If the full request has been sent,
106
+ # then the request is passed off to the `@app_pool` thread pool so that a "worker thread"
107
+ # can pick up the request and begin to execute application logic. This is done
108
+ # via `@app_pool << c`. The `Puma::Client` is then removed from the `sockets` array.
109
+ #
110
+ # If the request body is not present then nothing will happen, and the loop will iterate
111
+ # again. When the client sends more data to the socket the `Puma::Client` object will
112
+ # wake up the `NIO::Selector#select` and it can again be checked to see if it's ready to be
113
+ # passed to the thread pool.
114
+ #
115
+ # ## Time Out Case
116
+ #
117
+ # In addition to being woken via a write to one of the sockets the `NIO::Selector#select` will
118
+ # periodically "time out" of the sleep. One of the functions of this is to check for
119
+ # any requests that have "timed out". At the end of the loop it's checked to see if
120
+ # the first element in the `@timeout` array has exceed its allowed time. If so,
121
+ # the client object is removed from the timeout array, a 408 response is written.
122
+ # Then its connection is closed, and the object is removed from the `sockets` array
123
+ # that watches for new data.
124
+ #
125
+ # This behavior loops until all the objects that have timed out have been removed.
126
+ #
127
+ # Once all the timeouts have been processed, the next duration of the `NIO::Selector#select` sleep
128
+ # will be set to be equal to the amount of time it will take for the next timeout to occur.
129
+ # This calculation happens in `calculate_sleep`.
24
130
  def run_internal
25
- sockets = @sockets
131
+ monitors = @monitors
132
+ selector = @selector
26
133
 
27
134
  while true
28
135
  begin
29
- ready = IO.select sockets, nil, nil, @sleep_for
136
+ ready = selector.select @sleep_for
30
137
  rescue IOError => e
31
- if sockets.any? { |socket| socket.closed? }
138
+ Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
139
+ if monitors.any? { |mon| mon.value.closed? }
32
140
  STDERR.puts "Error in select: #{e.message} (#{e.class})"
33
141
  STDERR.puts e.backtrace
34
- sockets = sockets.reject { |socket| socket.closed? }
142
+
143
+ monitors.reject! do |mon|
144
+ if mon.value.closed?
145
+ selector.deregister mon.value
146
+ true
147
+ end
148
+ end
149
+
35
150
  retry
36
151
  else
37
152
  raise
38
153
  end
39
154
  end
40
155
 
41
- if ready and reads = ready[0]
42
- reads.each do |c|
43
- if c == @ready
156
+ if ready
157
+ ready.each do |mon|
158
+ if mon.value == @ready
44
159
  @mutex.synchronize do
45
160
  case @ready.read(1)
46
161
  when "*"
47
- sockets += @input
162
+ @input.each do |c|
163
+ mon = nil
164
+ begin
165
+ begin
166
+ mon = selector.register(c, :r)
167
+ rescue ArgumentError
168
+ # There is a bug where we seem to be registering an already registered
169
+ # client. This code deals with this situation but I wish we didn't have to.
170
+ monitors.delete_if { |submon| submon.value.to_io == c.to_io }
171
+ selector.deregister(c)
172
+ mon = selector.register(c, :r)
173
+ end
174
+ rescue IOError
175
+ # Means that the io is closed, so we should ignore this request
176
+ # entirely
177
+ else
178
+ mon.value = c
179
+ @timeouts << mon if c.timeout_at
180
+ monitors << mon
181
+ end
182
+ end
48
183
  @input.clear
184
+
185
+ @timeouts.sort! { |a,b| a.value.timeout_at <=> b.value.timeout_at }
186
+ calculate_sleep
49
187
  when "c"
50
- sockets.delete_if do |s|
51
- if s == @ready
188
+ monitors.reject! do |submon|
189
+ if submon.value == @ready
52
190
  false
53
191
  else
54
- s.close
192
+ submon.value.close
193
+ begin
194
+ selector.deregister submon.value
195
+ rescue IOError
196
+ # nio4r on jruby seems to throw an IOError here if the IO is closed, so
197
+ # we need to swallow it.
198
+ end
55
199
  true
56
200
  end
57
201
  end
@@ -60,40 +204,48 @@ module Puma
60
204
  end
61
205
  end
62
206
  else
207
+ c = mon.value
208
+
63
209
  # We have to be sure to remove it from the timeout
64
210
  # list or we'll accidentally close the socket when
65
211
  # it's in use!
66
212
  if c.timeout_at
67
213
  @mutex.synchronize do
68
- @timeouts.delete c
214
+ @timeouts.delete mon
69
215
  end
70
216
  end
71
217
 
72
218
  begin
73
219
  if c.try_to_finish
74
220
  @app_pool << c
75
- sockets.delete c
221
+ clear_monitor mon
76
222
  end
77
223
 
78
224
  # Don't report these to the lowlevel_error handler, otherwise
79
225
  # will be flooding them with errors when persistent connections
80
226
  # are closed.
81
227
  rescue ConnectionError
82
- c.write_500
228
+ c.write_error(500)
83
229
  c.close
84
230
 
85
- sockets.delete c
231
+ clear_monitor mon
86
232
 
87
233
  # SSL handshake failure
88
234
  rescue MiniSSL::SSLError => e
89
235
  @server.lowlevel_error(e, c.env)
90
236
 
91
237
  ssl_socket = c.io
92
- addr = ssl_socket.peeraddr.last
238
+ begin
239
+ addr = ssl_socket.peeraddr.last
240
+ # EINVAL can happen when browser closes socket w/security exception
241
+ rescue IOError, Errno::EINVAL
242
+ addr = "<unknown>"
243
+ end
244
+
93
245
  cert = ssl_socket.peercert
94
246
 
95
247
  c.close
96
- sockets.delete c
248
+ clear_monitor mon
97
249
 
98
250
  @events.ssl_error @server, addr, cert, e
99
251
 
@@ -101,19 +253,19 @@ module Puma
101
253
  rescue HttpParserError => e
102
254
  @server.lowlevel_error(e, c.env)
103
255
 
104
- c.write_400
256
+ c.write_error(400)
105
257
  c.close
106
258
 
107
- sockets.delete c
259
+ clear_monitor mon
108
260
 
109
261
  @events.parse_error @server, c.env, e
110
262
  rescue StandardError => e
111
263
  @server.lowlevel_error(e, c.env)
112
264
 
113
- c.write_500
265
+ c.write_error(500)
114
266
  c.close
115
267
 
116
- sockets.delete c
268
+ clear_monitor mon
117
269
  end
118
270
  end
119
271
  end
@@ -123,11 +275,13 @@ module Puma
123
275
  @mutex.synchronize do
124
276
  now = Time.now
125
277
 
126
- while @timeouts.first.timeout_at < now
127
- c = @timeouts.shift
128
- c.write_408 if c.in_data_phase
278
+ while @timeouts.first.value.timeout_at < now
279
+ mon = @timeouts.shift
280
+ c = mon.value
281
+ c.write_error(408) if c.in_data_phase
129
282
  c.close
130
- sockets.delete c
283
+
284
+ clear_monitor mon
131
285
 
132
286
  break if @timeouts.empty?
133
287
  end
@@ -138,6 +292,11 @@ module Puma
138
292
  end
139
293
  end
140
294
 
295
+ def clear_monitor(mon)
296
+ @selector.deregister mon.value
297
+ @monitors.delete mon
298
+ end
299
+
141
300
  public
142
301
 
143
302
  def run
@@ -149,6 +308,7 @@ module Puma
149
308
 
150
309
  def run_in_thread
151
310
  @thread = Thread.new do
311
+ Puma.set_thread_name "reactor"
152
312
  begin
153
313
  run_internal
154
314
  rescue StandardError => e
@@ -162,11 +322,21 @@ module Puma
162
322
  end
163
323
  end
164
324
 
325
+ # The `calculate_sleep` sets the value that the `NIO::Selector#select` will
326
+ # sleep for in the main reactor loop when no sockets are being written to.
327
+ #
328
+ # The values kept in `@timeouts` are sorted so that the first timeout
329
+ # comes first in the array. When there are no timeouts the default timeout is used.
330
+ #
331
+ # Otherwise a sleep value is set that is the same as the amount of time it
332
+ # would take for the first element to time out.
333
+ #
334
+ # If that value is in the past, then a sleep value of zero is used.
165
335
  def calculate_sleep
166
336
  if @timeouts.empty?
167
337
  @sleep_for = DefaultSleepFor
168
338
  else
169
- diff = @timeouts.first.timeout_at.to_f - Time.now.to_f
339
+ diff = @timeouts.first.value.timeout_at.to_f - Time.now.to_f
170
340
 
171
341
  if diff < 0.0
172
342
  @sleep_for = 0
@@ -176,17 +346,35 @@ module Puma
176
346
  end
177
347
  end
178
348
 
349
+ # This method adds a connection to the reactor
350
+ #
351
+ # Typically called by `Puma::Server` the value passed in
352
+ # is usually a `Puma::Client` object that responds like an IO
353
+ # object.
354
+ #
355
+ # The main body of the reactor loop is in `run_internal` and it
356
+ # will sleep on `NIO::Selector#select`. When a new connection is added to the
357
+ # reactor it cannot be added directly to the `sockets` array, because
358
+ # the `NIO::Selector#select` will not be watching for it yet.
359
+ #
360
+ # Instead what needs to happen is that `NIO::Selector#select` needs to be woken up,
361
+ # the contents of `@input` added to the `sockets` array, and then
362
+ # another call to `NIO::Selector#select` needs to happen. Since the `Puma::Client`
363
+ # object can be read immediately, it does not block, but instead returns
364
+ # right away.
365
+ #
366
+ # This behavior is accomplished by writing to `@trigger` which wakes up
367
+ # the `NIO::Selector#select` and then there is logic to detect the value of `*`,
368
+ # pull the contents from `@input` and add them to the sockets array.
369
+ #
370
+ # If the object passed in has a timeout value in `timeout_at` then
371
+ # it is added to a `@timeouts` array. This array is then re-arranged
372
+ # so that the first element to timeout will be at the front of the
373
+ # array. Then a value to sleep for is derived in the call to `calculate_sleep`
179
374
  def add(c)
180
375
  @mutex.synchronize do
181
376
  @input << c
182
377
  @trigger << "*"
183
-
184
- if c.timeout_at
185
- @timeouts << c
186
- @timeouts.sort! { |a,b| a.timeout_at <=> b.timeout_at }
187
-
188
- calculate_sleep
189
- end
190
378
  end
191
379
  end
192
380
 
@@ -195,6 +383,7 @@ module Puma
195
383
  begin
196
384
  @trigger << "c"
197
385
  rescue IOError
386
+ Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
198
387
  end
199
388
  end
200
389
 
@@ -202,6 +391,7 @@ module Puma
202
391
  begin
203
392
  @trigger << "!"
204
393
  rescue IOError
394
+ Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
205
395
  end
206
396
 
207
397
  @thread.join