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

HTTP server do SSL handshake in client fiber #9177

Merged
merged 6 commits into from
Apr 27, 2020

Conversation

waj
Copy link
Member

@waj waj commented Apr 25, 2020

This fixes #8108 by forcing the call to SSL_accept within the fiber that handles the request.

To implement this fix, I added the OpenSSL::SSL::Server#start_immediately property just like Ruby does: https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLServer.html

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

I'm not sure this is ideal, but for now it's good enough as a fix.

We'll need to revisit SSL::Server when we get to design a generic TLS API.

src/openssl/ssl/server.cr Outdated Show resolved Hide resolved
src/openssl/ssl/server.cr Show resolved Hide resolved
src/openssl/ssl/server.cr Outdated Show resolved Hide resolved
src/openssl/ssl/socket.cr Outdated Show resolved Hide resolved
@waj waj removed the pr:wip label Apr 26, 2020
@waj
Copy link
Member Author

waj commented Apr 26, 2020

Just added a spec and fixed the segfaults due to a double SSL_free call. Because now the accept is not called within the constructor, the finalizer will be executed correctly.

jhass
jhass previously approved these changes Apr 26, 2020
@straight-shoota straight-shoota added this to the 0.35.0 milestone Apr 26, 2020
raise ex
end

def accept
Copy link
Contributor

@RX14 RX14 Apr 26, 2020

Choose a reason for hiding this comment

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

Isn't this a breaking change for people using OpenSSL::SSL::Socket::Server?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true. I just refactored this fix so it doesn't break compatibility. Thanks!

RX14
RX14 previously approved these changes Apr 26, 2020
Copy link
Contributor

@RX14 RX14 left a comment

Choose a reason for hiding this comment

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

This is really ugly, and I still think that OpenSSL::SSL::Server needs to go, but it does improve the status quo.

@waj waj dismissed stale reviews from RX14, jhass, and straight-shoota via 6e59d98 April 26, 2020 16:06
@waj
Copy link
Member Author

waj commented Apr 26, 2020

@RX14 I agree with you, like I do with @straight-shoota. I just did the smallest change to fix this bug with the current design, but I'm also with you in that these wrappers around OpenSSL api is not ideal.

@636f7374
Copy link

Great!

@waj waj merged commit 03d7021 into crystal-lang:master Apr 27, 2020
@waj waj deleted the fix/http-server-ssl-accept-in-fiber branch April 27, 2020 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

openssl ssl_accept sometimes does not return, causes server to hang permanently
7 participants