Skip to content

Commit

Permalink
Don't let errors from closing override results
Browse files Browse the repository at this point in the history
Closing the connection is a courtesy for the remote end,
and one that is usually repayed by having the remote slam
shut, which causes us to error. Don't propogate those errors
to the user - instead only propagate errors from the read
and the write end.
  • Loading branch information
Keno committed Apr 15, 2020
1 parent 82f9b36 commit 5a118fe
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/StreamRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ function request(::Type{StreamLayer{Next}}, io::IO, request::Request, body;
writebody(http, request, body)
catch e
write_error = e
@info("Error in @async writebody task. " *
"Server likely closed the connection unexpectedly. " *
"Only an issue if unable to read the response and this error gets re-thrown. ",
exception=(write_error, catch_backtrace()))
isopen(io) && close(io)
isopen(io) && try; close(io); catch; end
end
yield()
@debug 2 "client startread"
Expand All @@ -74,7 +70,9 @@ function request(::Type{StreamLayer{Next}}, io::IO, request::Request, body;
end

if isaborted(http)
close(io)
# The server may have closed the connection.
# Don't propagate such errors.
try; close(io); catch; end
aborted = true
end
end
Expand All @@ -86,10 +84,15 @@ function request(::Type{StreamLayer{Next}}, io::IO, request::Request, body;
rethrow(e)
end
end
@debug 2 "client closewrite"
closewrite(http)
@debug 2 "client closeread"
closeread(http)

# Suppress errors from closing
try
@debug 2 "client closewrite"
closewrite(http)
@debug 2 "client closeread"
closeread(http)
catch;
end

verbose == 1 && printlncompact(response)
verbose == 2 && println(response)
Expand Down

0 comments on commit 5a118fe

Please sign in to comment.