Skip to content

Commit

Permalink
fix getting stuck when closing client
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauumm committed Nov 30, 2024
1 parent 9975c5c commit 23061f3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions extlibs/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ function HTTP:init(args)
-- [[
for _, server in ipairs(self.servers) do
assert(server:settimeout(0, "b"))
assert(server:settimeout(0, "t"))
end
--]]
end
Expand Down Expand Up @@ -498,7 +499,7 @@ end
function HTTP:handleClient(client)
local request = self:receive(client)
if not request then
return
return true
end

local increased_working = false
Expand Down Expand Up @@ -729,6 +730,7 @@ function HTTP:connectCoroutine(client, server)

if not self.block then
assert(client:settimeout(0, "b"))
assert(client:settimeout(0, "t"))
end

self:log(3, "waiting for handshake")
Expand Down Expand Up @@ -757,9 +759,10 @@ function HTTP:connectCoroutine(client, server)
self.clients[#self.clients + 1] = client
self:log(1, "total #clients", #self.clients)

self:handleClient(client)
self:log(1, "closing client...")
self:receive(client, 1)
if not self:handleClient(client) then
self:log(1, "closing client...")
self:receive(client, 1)
end
client:close()
for i = 1, #self.clients do
if self.clients[i] == client then
Expand Down Expand Up @@ -791,6 +794,7 @@ function HTTP:run()
-- [[ should the client be non-blocking as well? or can we assert the client will respond in time?
assert(client:setoption("keepalive", true))
assert(client:settimeout(0, "b"))
assert(client:settimeout(0, "t"))
--]]
local new_coroutine = coroutine.create(self.connectCoroutine)
local index = #coroutines + 1
Expand Down

0 comments on commit 23061f3

Please sign in to comment.