# HG changeset patch # User jbe # Date 1426780490 -3600 # Node ID ab51824e139b53a5cea3d8e79640d89fa0f94c9c # Parent e835cda61478aa6ac8442aaa7536c107b8515808 Added missing assert_io(...) for socket.output:close(); Close peer connection (with TCP RST) on I/O error diff -r e835cda61478 -r ab51824e139b moonbridge_http.lua --- a/moonbridge_http.lua Tue Mar 17 23:06:48 2015 +0100 +++ b/moonbridge_http.lua Thu Mar 19 16:54:50 2015 +0100 @@ -178,21 +178,27 @@ t[#t+1] = "" preamble = table.concat(t, "\r\n") end - local function assert_io(retval, errmsg) - if retval then - return retval - end - if options.io_error_handler then - options.io_error_handler(errmsg) - error(errmsg) - end - error(errmsg, 2) - end -- desired chunk sizes: local input_chunk_size = options.maximum_input_chunk_size or options.chunk_size or 16384 local output_chunk_size = options.minimum_output_chunk_size or options.chunk_size or 1024 -- return connect handler: return function(socket) + -- handing I/O errors: + local socket_closed = false + local function assert_io(retval, errmsg) + if retval then + return retval + end + if not socket_closed then + socket_closed = true + socket:cancel() + end + if options.io_error_handler then + options.io_error_handler(errmsg) + error(errmsg) + end + error(errmsg, 2) + end local survive = true -- set to false if process shall be terminated later repeat -- process named arguments "request_header_size_limit" and "request_body_size_limit": @@ -249,12 +255,13 @@ local function finish_response() if connection_close_responded then -- close output stream: - socket.output:close() + assert_io(socket.output:close()) -- wait for EOF of peer to avoid immediate TCP RST condition: timeout(2, function() while socket.input:read(input_chunk_size) do end end) -- fully close socket: + socket_closed = true -- avoid double close on error assert_io(socket:close()) else assert_io(socket:flush())