mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Test adding connection to Reactor after shutdown [changelog skip] (#2418)
* Test adding connection to Reactor after shutdown Modifies `TestPumaServer#shutdown_requests` to pause `Reactor#add` until after shutdown begins, to ensure requests are handled correctly for this edge case. Adds unit-test coverage for the fix introduced in #2377 and updated in #2279. * Fix Queue#close implementation for Ruby 2.2 Allow `ClosedQueueError` to be raised when `Queue#<<` is called. * Pass `@block` directly instead of `@block.method(:call)`
This commit is contained in:
parent
9ab7a3f2ea
commit
761fbafb8d
3 changed files with 19 additions and 2 deletions
|
@ -18,6 +18,7 @@ unless Queue.instance_methods.include?(:close)
|
|||
raise ClosedQueueError if @closed
|
||||
super
|
||||
end
|
||||
alias << push
|
||||
end
|
||||
Queue.prepend QueueClose
|
||||
end
|
||||
|
|
|
@ -84,7 +84,7 @@ module Puma
|
|||
retry
|
||||
end
|
||||
# Wakeup all remaining objects on shutdown.
|
||||
@timeouts.each(&@block.method(:call))
|
||||
@timeouts.each(&@block)
|
||||
@selector.close
|
||||
end
|
||||
|
||||
|
|
|
@ -972,6 +972,22 @@ EOF
|
|||
[204, {}, []]
|
||||
}
|
||||
|
||||
pool = @server.instance_variable_get(:@thread_pool)
|
||||
|
||||
# Trigger potential race condition by pausing Reactor#add until shutdown begins.
|
||||
if options.fetch(:queue_requests, true)
|
||||
reactor = @server.instance_variable_get(:@reactor)
|
||||
reactor.instance_variable_set(:@pool, pool)
|
||||
reactor.extend(Module.new do
|
||||
def add(client)
|
||||
if client.env['REQUEST_PATH'] == '/s2'
|
||||
Thread.pass until @pool.instance_variable_get(:@shutdown)
|
||||
end
|
||||
super
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
s1 = nil
|
||||
s2 = send_http post ?
|
||||
"POST /s2 HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nContent-Length: 5\r\n\r\nhi!" :
|
||||
|
@ -982,7 +998,7 @@ EOF
|
|||
app_finished.signal if s1_complete
|
||||
end
|
||||
@server.stop
|
||||
Thread.pass until @server.instance_variable_get(:@thread_pool).instance_variable_get(:@shutdown)
|
||||
Thread.pass until pool.instance_variable_get(:@shutdown)
|
||||
|
||||
assert_match(s1_response, s1.gets) if s1_response
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue