Skip to content

Commit

Permalink
Don't consider closes on reused sockets hard-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Jun 25, 2015
1 parent 032b5e0 commit fc9af15
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion deps/coro-http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ local function getConnection(host, port, tls)
table.remove(connections, i)
-- Make sure the connection is still alive before reusing it.
if not connection.socket:is_closing() then
connection.reused = true
return connection
end
end
Expand Down Expand Up @@ -127,7 +128,16 @@ function exports.request(method, url, headers, body)
write(req)
if body then write(body) end
local res = read()
if not res then error("Connection closed") end
if not res then
write()
-- If we get an immediate close on a reused socket, try again with a new socket.
-- TODO: think about if this could resend requests with side effects and cause
-- them to double execute in the remote server.
if connection.reused then
return exports.request(method, url, headers, body)
end
error("Connection closed")
end

body = {}
local continue = false
Expand Down

0 comments on commit fc9af15

Please sign in to comment.