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

Fix errant closing of sockets

This commit is contained in:
Evan Phoenix 2012-07-30 17:12:23 -06:00
parent 765eed127a
commit 6b72885be6

View file

@ -29,6 +29,13 @@ module Puma
@input.clear
end
else
# We have to be sure to remove it from the timeout
# list or we'll accidentally close the socket when
# it's in use!
if c.timeout_at
@timeouts.delete c
end
begin
if c.try_to_finish
@app_pool << c
@ -57,11 +64,10 @@ module Puma
sockets.delete c
c.close
if @timeouts.empty?
@sleep_for = DefaultSleepFor
break
end
break if @timeouts.empty?
end
calculate_sleep
end
end
end
@ -70,6 +76,20 @@ module Puma
@thread = Thread.new { run }
end
def calculate_sleep
if @timeouts.empty?
@sleep_for = DefaultSleepFor
else
diff = @timeouts.first.timeout_at.to_f - Time.now.to_f
if diff < 0.0
@sleep_for = 0
else
@sleep_for = diff
end
end
end
def add(c)
@mutex.synchronize do
@input << c
@ -78,13 +98,8 @@ module Puma
if c.timeout_at
@timeouts << c
@timeouts.sort! { |a,b| a.timeout_at <=> b.timeout_at }
diff = @timeouts.first.timeout_at.to_f - Time.now.to_f
if diff < 0.0
@sleep_for = 0
else
@sleep_for = diff
end
calculate_sleep
end
end
end