1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Move around some code and deal with test failures

This commit is contained in:
Evan Phoenix 2019-02-20 08:42:33 -08:00
parent e83a4954e4
commit d68f4b4933
2 changed files with 43 additions and 22 deletions

View file

@ -64,6 +64,8 @@ module Puma
@peerip = nil @peerip = nil
@remote_addr_header = nil @remote_addr_header = nil
@body_remain = 0
end end
attr_reader :env, :to_io, :body, :io, :timeout_at, :ready, :hijacked, attr_reader :env, :to_io, :body, :io, :timeout_at, :ready, :hijacked,
@ -102,6 +104,7 @@ module Puma
@tempfile = nil @tempfile = nil
@parsed_bytes = 0 @parsed_bytes = 0
@ready = false @ready = false
@body_remain = 0
if @buffer if @buffer
@parsed_bytes = @parser.execute(@env, @buffer, @parsed_bytes) @parsed_bytes = @parser.execute(@env, @buffer, @parsed_bytes)
@ -114,10 +117,17 @@ module Puma
end end
return false return false
elsif fast_check && else
begin
if fast_check &&
IO.select([@to_io], nil, nil, FAST_TRACK_KA_TIMEOUT) IO.select([@to_io], nil, nil, FAST_TRACK_KA_TIMEOUT)
return try_to_finish return try_to_finish
end end
rescue IOError
# swallow it
end
end
end end
def close def close
@ -294,7 +304,7 @@ module Puma
data = @io.read_nonblock(CHUNK_SIZE) data = @io.read_nonblock(CHUNK_SIZE)
rescue Errno::EAGAIN rescue Errno::EAGAIN
return false return false
rescue SystemCallError, IOError rescue SystemCallError, IOError, EOFError
raise ConnectionError, "Connection error detected during read" raise ConnectionError, "Connection error detected during read"
end end

View file

@ -62,7 +62,7 @@ module Puma
@timeouts = [] @timeouts = []
mon = @selector.register(@ready, :r) mon = @selector.register(@ready, :r)
mon.value = :wakeup mon.value = @ready
@sockets = [mon] @sockets = [mon]
end end
@ -154,19 +154,32 @@ module Puma
if ready if ready
ready.each do |m| ready.each do |m|
if m.value == :wakeup if m.value == @ready
@mutex.synchronize do @mutex.synchronize do
case @ready.read(1) case @ready.read(1)
when "*" when "*"
sockets += @input.map { |i| sockets.concat(@input.map { |c|
mon = selector.register(i, :r) mon = nil
mon.value = i begin
mon = selector.register(c, :r)
rescue ArgumentError
sockets.delete_if { |sm| sm.value.to_io == c.to_io }
selector.deregister(c)
mon = selector.register(c, :r)
end
mon.value = c
@timeouts << mon if c.timeout_at
sockets << mon
mon mon
} })
@input.clear @input.clear
@timeouts.sort! { |a,b| a.value.timeout_at <=> b.value.timeout_at }
calculate_sleep
when "c" when "c"
sockets.delete_if do |sm| sockets.delete_if do |sm|
if sm.value == :wakeup if sm.value == @ready
false false
else else
sm.value.close sm.value.close
@ -186,7 +199,7 @@ module Puma
# it's in use! # it's in use!
if c.timeout_at if c.timeout_at
@mutex.synchronize do @mutex.synchronize do
@timeouts.delete c @timeouts.delete m
end end
end end
@ -212,7 +225,12 @@ module Puma
@server.lowlevel_error(e, c.env) @server.lowlevel_error(e, c.env)
ssl_socket = c.io ssl_socket = c.io
begin
addr = ssl_socket.peeraddr.last addr = ssl_socket.peeraddr.last
rescue IOError
addr = "<unknown>"
end
cert = ssl_socket.peercert cert = ssl_socket.peercert
c.close c.close
@ -249,7 +267,7 @@ module Puma
@mutex.synchronize do @mutex.synchronize do
now = Time.now now = Time.now
while @timeouts.first.timeout_at < now while @timeouts.first.value.timeout_at < now
m = @timeouts.shift m = @timeouts.shift
c = m.value c = m.value
c.write_408 if c.in_data_phase c.write_408 if c.in_data_phase
@ -305,7 +323,7 @@ module Puma
if @timeouts.empty? if @timeouts.empty?
@sleep_for = DefaultSleepFor @sleep_for = DefaultSleepFor
else else
diff = @timeouts.first.timeout_at.to_f - Time.now.to_f diff = @timeouts.first.value.timeout_at.to_f - Time.now.to_f
if diff < 0.0 if diff < 0.0
@sleep_for = 0 @sleep_for = 0
@ -344,13 +362,6 @@ module Puma
@mutex.synchronize do @mutex.synchronize do
@input << c @input << c
@trigger << "*" @trigger << "*"
if c.timeout_at
@timeouts << c
@timeouts.sort! { |a,b| a.timeout_at <=> b.timeout_at }
calculate_sleep
end
end end
end end