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

Use Base.IOError in closewrite #260

Merged
merged 5 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function show(io::IO, err::MbedException)
end

mbed_err(ret) = throw(MbedException(ret))
mbed_ioerr(ret) = throw(Base.IOError(strerror(ret), ret))

function strerror(ret, bufsize=1000)
buf = Vector{UInt8}(undef, bufsize)
Expand Down
13 changes: 7 additions & 6 deletions src/ssl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function handshake(ctx::SSLContext)
end
else
ssl_abandon(ctx) ;@💀 "🤝 💥"
throw(MbedException(n))
mbed_ioerr(n)
end
end
;@😬 "🤝 ✅"
Expand Down Expand Up @@ -108,7 +108,7 @@ function ssl_abandon(ctx::SSLContext)
ctx.close_notify_sent = true
close(ctx.bio)
n = ssl_session_reset(ctx)
n == 0 || throw(MbedException(n))
n == 0 || mbed_ioerr(n)
nothing
end

Expand Down Expand Up @@ -202,7 +202,7 @@ function closewrite(ctx::SSLContext)
"never returns ...WANT_READ/WRITE."
elseif n != 0
ssl_abandon(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, as I commented on in the related PR, the problem here is ssl_abandon is going to throw before we're able to throw the IOError on the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks that make sense. However ssl_abandon doesn't throw in my scenario (#259) where I reliably end up here with n = -80, strerror(n) = NET - Connection was reset by peer.

So the issue is resolved for me.

Would you like me to replace MbedException(n) with Base.IOError(strerror(n), n) in ssl_abandon anyways?

Should we also make the swap in handshake while at it? That's the last remaining reference to MbedException in this file.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's switch them all to IOError; thanks.

throw(MbedException(n))
mbed_ioerr(n)
elseif !ctx.isreadable
# already seen EOF, so we can go ahead and destroy this now immediately
close(ctx.bio)
Expand Down Expand Up @@ -234,7 +234,7 @@ function ssl_unsafe_write(ctx::SSLContext, buf::Ptr{UInt8}, nbytes::UInt)
continue
elseif n < 0
ssl_abandon(ctx) ;@🤖 "ssl_write 💥"
throw(Base.IOError(strerror(n), n))
mbed_ioerr(n)
end
nwritten += n
end
Expand Down Expand Up @@ -326,7 +326,7 @@ When TLS `close_notify` is received:
[RFC5246 7.2.1]: "Any data received after a closure alert is ignored."
- the number of bytes read before the `close_notify` is returned as usual.

Throws a `MbedException` if `ssl_read` returns an unhandled error code.
Throws a `IOError` if `ssl_read` returns an unhandled error code.

When an unhandled exception occurs `isreadable` is set to false.
"""
Expand Down Expand Up @@ -361,7 +361,8 @@ function ssl_unsafe_read(ctx::SSLContext, buf::Ptr{UInt8}, nbytes::UInt)
ctx.bytesavailable = 0 ;@😬 "ssl_read ⌛️ $nread"
return nread
elseif n < 0
throw(Base.IOError(strerror(n), n))
ssl_abandon(ctx)
mbed_ioerr(n)
end

nread += n
Expand Down