I have created a simple web server using HTTP.jl for handling high-volume, low-latency simple requests. For performance, I spawn a separate thread on :default for each request.
Everything runs fine but after running tests using 200 concurrent connections, I get the following error when the requester stops sending requests:
┌ Error: handle_connection handler error.
│
│ ===========================
│ HTTP Error message:
│
│ ERROR: IOError: write: connection reset by peer (ECONNRESET)
│ Stacktrace:
│ [1] uv_write(s::Sockets.TCPSocket, p::Ptr{UInt8}, n::UInt64)
---- removed as forum software thought I was posting links
│
│ “”"
└ @ HTTP.Servers ~/usr/local/julia/reg/packages/HTTP/sJD5V/src/Servers.jl:483
I am not so concerned about the error itself as it could be that the test tool is dropping the connection. However, I am trying to catch these errors so it doesn’t clutter my logs, since this application could have thousands of connections. Here is the basic structure of the app:
function main()
global server_ready, http_server_port, http_max_conns, http_readtimeout
try
server_ready = true
HTTP.serve(ROUTER, “0.0.0.0”, http_server_port, stream=true, max_connections=http_max_conns, readtimeout=http_readtimeout)
catch
if isa(e, Base.IOError) && e.code == Base.UV_EPIPE
println(“Broken Pipe Error - Ignored”)
else
rethrow()
end
end
end
try
main()
catch e
println(“Error in main server loop”)
showerror(stdout, e)
end
However, when the connection reset error occurs, it is not caught by my exception handling code, regardless of how I structure it.
What exactly is your desired output? If I understand correctly, your code should print "Broken Pipe Error - Ignored" if you encounter the error you mentioned, but keep running? What is the behavior you see instead? (exception/no exception; exact error message)
I think your code as-is should probably throw an UndefVarError if the HTTP error occurs because your catch block inside main() doesn’t assign the variable e. Are there some parts of the code missing?
Thanks for the reply. I will pay more attention to formatting in future posts.
You are correct with what I am looking to see but what I get is either the handle connection error I posted or an equivalent Broken Pipe error.
Your second point is also correct (thanks!) but reinforces the idea that the exception isn’t being caught by my try/catch. I have fixed it and will test again to see if the try/catch was being ignored because of this.
Errors that are wrapped in a bracket like that probably come from the @error logging macros. The underlying exception is handled and logged by the underlying library and not available to the calling code. There’s presumably a non-exception-handling way to retrieve the status for an HTTP error for programmatic handling of the error.
EDIT: And also probably a way to control the logging of said errors.