mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add timeout support to persistent connections
This commit is contained in:
parent
40dac162a2
commit
44cd2583aa
4 changed files with 28 additions and 0 deletions
1
README.txt
Symbolic link
1
README.txt
Symbolic link
|
@ -0,0 +1 @@
|
|||
README.md
|
|
@ -56,6 +56,11 @@ module Puma
|
|||
# REMOTE_USER, or REMOTE_HOST parameters since those are either a security problem or
|
||||
# too taxing on performance.
|
||||
module Const
|
||||
|
||||
# The default number of seconds for another request within a persistent
|
||||
# session.
|
||||
PERSISTENT_TIMEOUT = 20
|
||||
|
||||
DATE = "Date".freeze
|
||||
|
||||
SCRIPT_NAME = "SCRIPT_NAME".freeze
|
||||
|
|
|
@ -21,6 +21,7 @@ module Puma
|
|||
|
||||
attr_accessor :min_threads
|
||||
attr_accessor :max_threads
|
||||
attr_accessor :persistent_timeout
|
||||
|
||||
# Creates a working server on host:port (strange things happen if port
|
||||
# isn't a Number).
|
||||
|
@ -43,6 +44,8 @@ module Puma
|
|||
@thread = nil
|
||||
@thread_pool = nil
|
||||
|
||||
@persistent_timeout = PERSISTENT_TIMEOUT
|
||||
|
||||
@proto_env = {
|
||||
"rack.version".freeze => Rack::VERSION,
|
||||
"rack.errors".freeze => events.stderr,
|
||||
|
@ -140,6 +143,10 @@ module Puma
|
|||
|
||||
if parser.finished?
|
||||
return unless handle_request env, client, parser.body
|
||||
|
||||
unless IO.select([client], nil, nil, @persistent_timeout)
|
||||
raise EOFError, "Timed out persistent connection"
|
||||
end
|
||||
else
|
||||
# Parser is not done, queue up more data to read and continue parsing
|
||||
chunk = client.readpartial(CHUNK_SIZE)
|
||||
|
|
|
@ -93,4 +93,19 @@ class TestPersistent < Test::Unit::TestCase
|
|||
assert_equal "Hello", @client.read(5)
|
||||
end
|
||||
|
||||
def test_persistent_timeout
|
||||
@server.persistent_timeout = 2
|
||||
@client << @valid_request
|
||||
sz = @body[0].size.to_s
|
||||
|
||||
assert_equal "HTTP/1.1 200 OK\r\nContent-Length: #{sz}\r\nX-Header: Works\r\n\r\n", lines(4)
|
||||
assert_equal "Hello", @client.read(5)
|
||||
|
||||
sleep 3
|
||||
|
||||
assert_raises EOFError do
|
||||
@client.read_nonblock(1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue