diff --git a/lib/puma/const.rb b/lib/puma/const.rb index 3763f3d2..e8af97b7 100644 --- a/lib/puma/const.rb +++ b/lib/puma/const.rb @@ -41,6 +41,10 @@ module Puma # for the request FIRST_DATA_TIMEOUT = 30 + # How long to wait when getting some write blocking on the socket when + # sending data back + WRITE_TIMEOUT = 10 + DATE = "Date".freeze SCRIPT_NAME = "SCRIPT_NAME".freeze diff --git a/lib/puma/server.rb b/lib/puma/server.rb index f848998e..4ddd7c43 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -779,10 +779,13 @@ module Puma begin n = io.syswrite str rescue Errno::EAGAIN, Errno::EWOULDBLOCK - IO.select(nil, [io], nil, 1) + if !IO.select(nil, [io], nil, WRITE_TIMEOUT) + raise ConnectionError, "Socket timeout writing data" + end + retry rescue Errno::EPIPE, SystemCallError, IOError - return false + raise ConnectionError, "Socket timeout writing data" end return if n == str.bytesize