Skip to content

Commit 581c6fc

Browse files
Don't collect exception stack for log messages that won't be written out (#1150)
* Don't collect exception stack if it won't be logged * Bump version
1 parent 7801db8 commit 581c6fc

File tree

6 files changed

+30
-23
lines changed

6 files changed

+30
-23
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HTTP"
22
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
33
authors = ["Jacob Quinn", "contributors: https://github.com/JuliaWeb/HTTP.jl/graphs/contributors"]
4-
version = "1.10.1"
4+
version = "1.10.2"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/Servers.jl

+20-10
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ function shutdown(fn::Function)
193193
try
194194
fn()
195195
catch
196-
msg = current_exceptions_to_string()
197-
@error "shutdown function $fn failed. $msg"
196+
@error begin
197+
msg = current_exceptions_to_string()
198+
"shutdown function $fn failed. $msg"
199+
end
198200
end
199201
end
200202

@@ -393,8 +395,10 @@ function listenloop(f, listener, conns, tcpisvalid,
393395
if e isa Base.IOError && e.code == Base.UV_ECONNABORTED
394396
verbose >= 0 && @infov 1 "Server on $(listener.hostname):$(listener.hostport) closing"
395397
else
396-
msg = current_exceptions_to_string()
397-
@errorv 2 "Server on $(listener.hostname):$(listener.hostport) errored. $msg"
398+
@errorv 2 begin
399+
msg = current_exceptions_to_string()
400+
"Server on $(listener.hostname):$(listener.hostport) errored. $msg"
401+
end
398402
# quick little sleep in case there's a temporary
399403
# local error accepting and this might help avoid quickly re-erroring
400404
sleep(0.05 + rand() * 0.05)
@@ -433,8 +437,10 @@ function handle_connection(f, c::Connection, listener, readtimeout, access_log)
433437
if e isa ParseError
434438
write(c, Response(e.code == :HEADER_SIZE_EXCEEDS_LIMIT ? 431 : 400, string(e.code)))
435439
end
436-
msg = current_exceptions_to_string()
437-
@debugv 1 "handle_connection startread error. $msg"
440+
@debugv 1 begin
441+
msg = current_exceptions_to_string()
442+
"handle_connection startread error. $msg"
443+
end
438444
break
439445
end
440446

@@ -461,8 +467,10 @@ function handle_connection(f, c::Connection, listener, readtimeout, access_log)
461467
# The remote can close the stream whenever it wants to, but there's nothing
462468
# anyone can do about it on this side. No reason to log an error in that case.
463469
level = e isa Base.IOError && !isopen(c) ? Logging.Debug : Logging.Error
464-
msg = current_exceptions_to_string()
465-
@logmsgv 1 level "handle_connection handler error. $msg"
470+
@logmsgv 1 level begin
471+
msg = current_exceptions_to_string()
472+
"handle_connection handler error. $msg"
473+
end
466474

467475
if isopen(http) && !iswritable(http)
468476
request.response.status = 500
@@ -478,8 +486,10 @@ function handle_connection(f, c::Connection, listener, readtimeout, access_log)
478486
end
479487
catch
480488
# we should be catching everything inside the while loop, but just in case
481-
msg = current_exceptions_to_string()
482-
@errorv 1 "error while handling connection. $msg"
489+
@errorv 1 begin
490+
msg = current_exceptions_to_string()
491+
"error while handling connection. $msg"
492+
end
483493
finally
484494
if readtimeout > 0
485495
wait_for_timeout[] = false

src/WebSockets.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,10 @@ function upgrade(f::Function, http::Streams.Stream; suppress_close_error::Bool=f
440440
f(ws)
441441
catch e
442442
if !isok(e)
443-
msg = current_exceptions_to_string()
444-
suppress_close_error || @error "$(ws.id): Unexpected websocket server error. $msg"
443+
suppress_close_error || @error begin
444+
msg = current_exceptions_to_string()
445+
"$(ws.id): Unexpected websocket server error. $msg"
446+
end
445447
end
446448
if !isclosed(ws)
447449
if e isa WebSocketError && e.message isa CloseFrameBody

src/clientlayers/ConnectionRequest.jl

+3-6
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ function connectionlayer(handler)
8080
io = newconnection(IOType, url.host, url.port; readtimeout=readtimeout, connect_timeout=connect_timeout, kw...)
8181
catch e
8282
if logerrors
83-
msg = current_exceptions_to_string()
84-
@error msg type=Symbol("HTTP.ConnectError") method=req.method url=req.url context=req.context logtag=logtag
83+
@error current_exceptions_to_string() type=Symbol("HTTP.ConnectError") method=req.method url=req.url context=req.context logtag=logtag
8584
end
8685
req.context[:connect_errors] = get(req.context, :connect_errors, 0) + 1
8786
throw(ConnectError(string(url), e))
@@ -127,12 +126,10 @@ function connectionlayer(handler)
127126
root_err = ExceptionUnwrapping.unwrap_exception_to_root(e)
128127
# don't log if it's an HTTPError since we should have already logged it
129128
if logerrors && root_err isa StatusError
130-
msg = current_exceptions_to_string()
131-
@error msg type=Symbol("HTTP.StatusError") method=req.method url=req.url context=req.context logtag=logtag
129+
@error current_exceptions_to_string() type=Symbol("HTTP.StatusError") method=req.method url=req.url context=req.context logtag=logtag
132130
end
133131
if logerrors && !ExceptionUnwrapping.has_wrapped_exception(e, HTTPError)
134-
msg = current_exceptions_to_string()
135-
@error msg type=Symbol("HTTP.ConnectionRequest") method=req.method url=req.url context=req.context logtag=logtag
132+
@error current_exceptions_to_string() type=Symbol("HTTP.ConnectionRequest") method=req.method url=req.url context=req.context logtag=logtag
136133
end
137134
@debugv 1 "❗️ ConnectionLayer $root_err. Closing: $io"
138135
if @isdefined(stream) && stream.nwritten == -1

src/clientlayers/StreamRequest.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ function streamlayer(stream::Stream; iofunction=nothing, decompress::Union{Nothi
7272
if timedout === nothing || !timedout[]
7373
req.context[:io_errors] = get(req.context, :io_errors, 0) + 1
7474
if logerrors
75-
msg = current_exceptions_to_string()
76-
@error msg type=Symbol("HTTP.IOError") method=req.method url=req.url context=req.context logtag=logtag
75+
@error current_exceptions_to_string() type=Symbol("HTTP.IOError") method=req.method url=req.url context=req.context logtag=logtag
7776
end
7877
end
7978
rethrow()

src/clientlayers/TimeoutRequest.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function timeoutlayer(handler)
2626
req = stream.message.request
2727
req.context[:timeout_errors] = get(req.context, :timeout_errors, 0) + 1
2828
if logerrors
29-
msg = current_exceptions_to_string()
30-
@error msg type=Symbol("HTTP.TimeoutError") method=req.method url=req.url context=req.context timeout=readtimeout logtag=logtag
29+
@error current_exceptions_to_string() type=Symbol("HTTP.TimeoutError") method=req.method url=req.url context=req.context timeout=readtimeout logtag=logtag
3130
end
3231
e = Exceptions.TimeoutError(readtimeout)
3332
end

0 commit comments

Comments
 (0)