Closed bbblitz closed 4 years ago
instead of raising an error here, would it make more sense to log a warning instead? that way a client connection error doesnt exit the main loop
@skwerlman but if the error happened in server:accept()
, how would handle this case? if you have a solution for it, can you show me how would be the code?
Thanks for the contribution @skwerlman and @bbblitz
@skwerlman but if the error happened in
server:accept()
, how would handle this case? if you have a solution for it, can you show me how would be the code?
I expect he means something like this:
local client, errmsg = server:accept()
if not client then
print("Failed to accept connection:" .. errmsg)
end
...
And he's right, the web server really shouldn't crash in the middle of operation, @skwerlman do you want to make the PR or should I?
@bbblitz could you update your PR with your last code? I'd love to merge this solution. Thanks a lot
Maybe it should not be using print
, but instead do:
io.stderr:write("Failed to accept connection:" .. errmsg .. "\n")
Huh, it automatically adds my commits instead of letting me clean them up first. Oh well.
@bbblitz @skwerlman @Tieske fantastic guys! Thanks a lot!
In some cases, server:accept() can fail, when it does it returns nil + an error message. When it fails, display the error instead of failing to index nil on the next line.