Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture async error in writebody(http, request, body) #285

Merged
merged 5 commits into from
Sep 7, 2018

Conversation

samoconnor
Copy link
Contributor

@samoconnor samoconnor requested a review from quinnj August 22, 2018 00:36
@codecov-io
Copy link

codecov-io commented Aug 29, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@55b7acb). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #285   +/-   ##
=========================================
  Coverage          ?   90.37%           
=========================================
  Files             ?       29           
  Lines             ?     1185           
  Branches          ?        0           
=========================================
  Hits              ?     1071           
  Misses            ?      114           
  Partials          ?        0
Impacted Files Coverage Δ
src/StreamRequest.jl 88.88% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55b7acb...b392696. Read the comment docs.

catch e
write_error = e
@warn("Error in @async writebody task",
exception=(write_error, catch_backtrace()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be stacktrace(catch_backtrace())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way because the @warn macro seems to do special processing of Tuple{Exception,BackTrace}. i.e. it prints out a nice stack-trace.

if e isa CompositeException
e = first(e.exceptions).ex
if write_error != nothing
throw(write_error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this changing behavior from before? Didn't we pass on to the next if block before and check is it's a isioerror. Why change that now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, looking at this again, I think there is more to it...

Assume that writebody is sending some huge message body, and the server sends an error with Connection: "close (https://tools.ietf.org/html/rfc7230#section-6.5).
readbody will return, and isaborted() will be true on line 72.
So, close gets called and the writebody task stop with an IO error, which is stored in write_error.
However, the catch block at 79 will never be reached, because there is no exception to catch in the main task, so write_error will not be used at all. This makes sense in this case because the main task has decided to kill the writebody task and doesn't care about any subsequent exceptions that it might throw.

I think we can reduce the catch block to just:

    catch e
        if write_error != nothing
            throw(write_error)
        else
            rethrow(e)
        end
    end

This makes the intent of the code a bit easier to follow, i.e: If there is an error while reading the response, check if the root-cause was an error sending the request, otherwise just rethrow the reading error.

@quinnj
Copy link
Member

quinnj commented Sep 7, 2018

Rebased.

@quinnj quinnj merged commit 3df42f5 into master Sep 7, 2018
@quinnj quinnj deleted the writebody_exception branch September 7, 2018 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants