Skip to content

Commit d254321

Browse files
committed
http/server: close connection on unhandled internal errors
Fixes: #146 I'm not sure if implementation is correct, or if it best way to handle it. In any case it fixes client-visible problem where lua-http server keep connection open even after internal error (like #145).
1 parent bc49a4b commit d254321

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

http/server.lua

+10-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,16 @@ local function handle_socket(self, socket)
152152
while true do
153153
local timeout = deadline and deadline-monotime() or self.intra_stream_timeout
154154
local stream
155-
stream, err, errno = conn:get_next_incoming_stream(timeout)
155+
local stream_or_err
156+
local finished
157+
finished, stream_or_err, err, errno = xpcall(conn.get_next_incoming_stream, debug.traceback, conn, timeout)
158+
if not finished then -- uncaught internal error, terminate connection
159+
err = stream_or_err
160+
errno = ce.EFAULT
161+
stream = nil
162+
else
163+
stream = stream_or_err
164+
end
156165
if stream == nil then
157166
if (err ~= nil -- client closed connection
158167
and errno ~= ce.ECONNRESET

0 commit comments

Comments
 (0)