You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code will loop infinitely when you make a request to the server. onstream and onerror are called endlessly, the requesting client hangs. There doesn't appear to be a way to finalize the stream in the error handler based on what I've looked at so far.
I would expect it to terminate the request with a 503 error, as if you had triggered an error after getting headers.
My guess that is that since the stream doesn't make any progress being processed in the stream handler before error it's re-queued to be processed again, hence the infinite loop.
Note: It's necessary to provide a custom onerror function, as the default one will terminate the entire server by throwing an error.
localhttp_server=require"http.server"localhttp_headers=require"http.headers"localfunctiononstream(server, stream)
error("throwing an error before get_headers will cause infinite loop!")
localreq_headers=stream:get_headers()
error("this is fine") -- error after get_headers will terminate request with 503 error as expectedendlocalserver=assert(http_server.listen {
host="127.0.0.1";
port=8080;
onstream=onstream;
onerror=function(myserver, context, op, err, errno)
localmsg=op.." on " ..tostring(context) .." failed"iferrthenmsg=msg..": " ..tostring(err)
endassert(io.stderr:write(msg, "\n"))
end;
})
assert(server:loop())
The text was updated successfully, but these errors were encountered:
onstream fires when there is a request ready to be handled: if not even a single byte of it is read, then onstream will fire again on the next main loop iteration.
If you haven't called get_headers, then it hasn't even started handling the request, and as such it can't terminate the request.
The following code will loop infinitely when you make a request to the server.
onstream
andonerror
are called endlessly, the requesting client hangs. There doesn't appear to be a way to finalize the stream in the error handler based on what I've looked at so far.I would expect it to terminate the request with a 503 error, as if you had triggered an error after getting headers.
My guess that is that since the stream doesn't make any progress being processed in the stream handler before error it's re-queued to be processed again, hence the infinite loop.
Note: It's necessary to provide a custom
onerror
function, as the default one will terminate the entire server by throwing an error.The text was updated successfully, but these errors were encountered: