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

Take out extra, unnecessary isopen checks #255

Merged
merged 1 commit into from
Aug 25, 2022
Merged

Take out extra, unnecessary isopen checks #255

merged 1 commit into from
Aug 25, 2022

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Aug 24, 2022

We check Base.check_open, then iswritable checks isopen, and then we
check isopen again in f_send before we actually write. None of this is
particularly problematic except that if our bio isn't open in Base.check_open
then we get an IOError, but if iswritable fails, we get an ArgumentError.

By delaying the isopen check until f_send, I believe that will result in
a more predictable MbedException being thrown consistently.

I believe this was a source of the occasional unsafe_write requires iswritable(::SSLContext) error where it was actually just a data race between the first Base.check_open and the second isopen in iswritable.

We check `Base.check_open`, then `iswritable` checks `isopen`, and then we
check `isopen` again in `f_send` before we actually write. None of this is
particularly problematic except that if our bio isn't open in `Base.check_open`
then we get an `IOError`, but if `iswritable` fails, we get an `ArgumentError`.

By delaying the `isopen` check until `f_send`, I believe that will result in
a more predictable `MbedException` being thrown consistently.
@quinnj quinnj requested a review from vtjnash August 24, 2022 23:08
@codecov
Copy link

codecov bot commented Aug 24, 2022

Codecov Report

Merging #255 (97703b2) into master (22f5393) will decrease coverage by 0.31%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #255      +/-   ##
==========================================
- Coverage   74.06%   73.75%   -0.32%     
==========================================
  Files          12       12              
  Lines         721      720       -1     
==========================================
- Hits          534      531       -3     
- Misses        187      189       +2     
Impacted Files Coverage Δ
src/ssl.jl 72.60% <100.00%> (-0.10%) ⬇️
src/entropy.jl 80.76% <0.00%> (-3.85%) ⬇️
src/ctr_drbg.jl 81.48% <0.00%> (-3.71%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@quinnj quinnj merged commit ae22a9b into master Aug 25, 2022
@quinnj quinnj deleted the jq/cleanup branch August 25, 2022 13:14
Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

Lgtm


iswritable(ctx) ||
throw(ArgumentError("`unsafe_write` requires `iswritable(::SSLContext)`"))
ctx.close_notify_sent && throw(ArgumentError("`unsafe_write` requires `!ctx.close_notify_sent`"))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This would normally generate ECONRESET IOError for other IO objects

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, as I've been digging in to all this, I feel like I'd rather be throwing IOErrors instead of MbedExceptions in several places.

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.

2 participants