# HG changeset patch # User Waqas Hussain # Date 1361889712 -18000 # Node ID 760c345dc7a1711e73c94dd2715298ff19466b47 # Parent 5b73ac268a9eaa5533d1d90a119a9fde40417593 net.http.server: Ensure HTTP callbacks are never called recursively for pipelined requests. diff -r 5b73ac268a9e -r 760c345dc7a1 net/http/server.lua --- a/net/http/server.lua Mon Feb 18 13:12:14 2013 +0100 +++ b/net/http/server.lua Tue Feb 26 19:41:52 2013 +0500 @@ -89,29 +89,30 @@ local pending = {}; local waiting = false; local function process_next() - --if waiting then log("debug", "can't process_next, waiting"); return; end - if sessions[conn] and #pending > 0 then + if waiting then log("debug", "can't process_next, waiting"); return; end + waiting = true; + while sessions[conn] and #pending > 0 do local request = t_remove(pending); --log("debug", "process_next: %s", request.path); - waiting = true; --handle_request(conn, request, process_next); _1, _2, _3 = conn, request, process_next; if not xpcall(_handle_request, _traceback_handler) then conn:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = last_err })); conn:close(); end - else - --log("debug", "ready for more"); - waiting = false; end + --log("debug", "ready for more"); + waiting = false; end local function success_cb(request) --log("debug", "success_cb: %s", request.path); + if waiting then + log("error", "http connection handler is not reentrant: %s", request.path); + assert(false, "http connection handler is not reentrant"); + end request.secure = secure; t_insert(pending, request); - if not waiting then - process_next(); - end + process_next(); end local function error_cb(err) log("debug", "error_cb: %s", err or "");