-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix SSL_shutdown error handling #3703
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
base: master
Are you sure you want to change the base?
Fix SSL_shutdown error handling #3703
Conversation
a177583
to
ce29e27
Compare
SSL_shutdown() call may result in error and in OpenSSL every error should be consumed by the valler via SSL_get_error() or a similar func. MiniSSL implementation was breaking this convention so it resulted in cryptic bugs like SSL clients (not related to Puma in any way) return errors with text like "SSL_read: shutdown while in init" that is initially generated by the Puma reactor but not consumed by it. Such bugs are really hard to debug...
ce29e27
to
c683c6c
Compare
Thanks for the PR! The C extension is probably the hardest area to modify, if you can give us some help validating your change I think this looks like a good quality of life improvement: Can you give me an example of a change in error output before and after? Ideally, if you have a reproduction that lets me exercise and view the error on my own that would be even better https://www.codetriage.com/reproduction. I tried pulling in the added tests into master/main I'm unable to use them to reproduce an error as they rely on additions from this PR:
Does this change modify or break an API? |
No just cherry pick the change in |
Well it's tricky. Before this change, Puma was not printing anything in the logs if However, the only bug I was able to catch is when To reproduce at least something you could apply the following patch on current
This is nearly the same as changes from my PR except the |
Besides of |
Well one could ask why do all this if nothing was changed anyway in terms of what error are reported in the logs. The problem is some OpenSSL library call resulted in error, it's a caller responsibility to consume this error from the error queue. |
If you don't consume the OpenSSL error from the queue, it might break the From the
|
Two tests I added in I added them just because I also introduced |
Yes, I didn't notice that right away. This PR seems correct. Reviewing OpenSSL man pages, may add a few tests to show that nothing is logged. |
Maybe add two tests to def test_http_10_close_no_errors
start_server
assert_equal 'https', send_http_read_response(GET_10, ctx: new_ctx).body
assert_empty @log_stderr.string
end
def test_http_11_close_no_errors
start_server
skt = send_http ctx: new_ctx
assert_equal 'https', skt.read_response.body
skt.close
assert_empty @log_stderr.string
end Also, rather than extract the code to begin
client.close if close_socket
rescue IOError, SystemCallError
# Already closed
rescue MiniSSL::SSLError => e
@log_writer.ssl_error e, client.io
rescue StandardError => e
@log_writer.unknown_error e, nil, "Client"
end |
It was extracted cause it has more than one call sites |
Sorry, also missed that. Jumping around a bit today... Can it be added to |
JFYI, as to my missing that, the new HTTP_10 test is called from Thanks for adding the tests. |
Please ignore the idea of moving code from |
Not sure what you checked. Some of this code is from 25-July-2016, OpenSSL 1.0.2h was the current version. I reviewed this with a few current OpenSSL man pages (see https://docs.openssl.org/master/man3/SSL_shutdown/). LGTM. |
SSL_shutdown()
call may result in error and in OpenSSL every error should be consumed by the valler viaSSL_get_error()
or a similar func.MiniSSL
implementation was breaking this convention so it resulted in cryptic bugs like SSL clients (not related to Puma in any way) return errors with text like"SSL_read: shutdown while in init"
that is initially generated by the Puma reactor but not consumed by it.Such bugs are really hard to debug...
Description
Thank you for contributing! You're the best.
We can read your code, so consider leaving some comments here that are more about your motivations and decision making. Some things that may be helpful to address in your description:
Your checklist for this pull request
[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.