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

server.rb - properly cork & uncork ssl clients #2550

Merged
merged 1 commit into from Feb 5, 2021

Conversation

MSP-Greg
Copy link
Member

@MSP-Greg MSP-Greg commented Feb 4, 2021

Description

Server##cork_socket & Server##uncork_socket work on TCPSockets, but when using an ssl client, a MiniSSL::Socket is passed to them.

Use 'to_io', which is available with all 'socket objects' used in Puma.

I haven't worked with wireshark for a while, and that's probably the only way to see a difference?

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added an entry to History.md if this PR fixes a bug or adds a feature. If it doesn't need an entry to HISTORY.md, I have added [changelog skip] or [ci skip] to the pull request title.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@nateberkopec nateberkopec added bug ssl waiting-for-review Waiting on review from anyone labels Feb 4, 2021
Socket.const_defined?(:IPPROTO_TCP) &&
Socket.const_defined?(:TCP_CORK)
end

# :nodoc:
# @version 5.0.0
def closed_socket_supported?
RbConfig::CONFIG['host_os'] =~ /linux/ &&
RbConfig::CONFIG['host_os'].include?('linux') &&
Copy link
Member

Choose a reason for hiding this comment

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

What's the motivation for the change here?

Copy link
Member Author

@MSP-Greg MSP-Greg Feb 4, 2021

Choose a reason for hiding this comment

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

General code improvement.

  1. If you need a boolean, choose a method that returns one. I think that was the reason String#match? was added in Ruby 2.4.
  2. Use string methods if a RegExp test isn't needed. If and when macOS supports 'cork' (and hence /linux|darwin/), it can be a string method.

Off topic: A long time ago, my first 'significant' contribution to 'OS Ruby' was working on building & testing Windows/MinGW Ruby. Since then, I've always kept an eye on the commits to ruby/ruby. There are a lot of commits there that include small code changes like the change above.

I can revert and/or add a 'History.md' line

Copy link
Member Author

@MSP-Greg MSP-Greg Feb 4, 2021

Choose a reason for hiding this comment

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

@nateberkopec

I looked at this a bit more, and SOCKET::TCP_CORK is not defined in Windows and macOS. So, a better solution might be to add HAS_TCP_CORK to detect.rb and add a conditional to the method calls? So:

cork_socket io
uncork_socket io

would change to:

cork_socket(io) if HAS_TCP_CORK
uncork_socket(io) if HAS_TCP_CORK

Not sure, ::Puma::HAS_TCP_CORK might be a bit faster, but simple conditionals run much quick that method calls, etc...

Copy link
Member Author

Choose a reason for hiding this comment

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

Ran ruby -rsocket -e 'puts Socket.constants.sort' in CI, and updated the code based on that. The needed constants are not defined in Windows or macOS, so removed the linux detection...

@nateberkopec nateberkopec added the waiting-for-changes Waiting on changes from the requestor label Feb 4, 2021
@MSP-Greg MSP-Greg changed the title server.rb - properly cork & uncork ssl clients [changelog skip] server.rb - properly cork & uncork ssl clients Feb 4, 2021
@@ -19,7 +21,6 @@
* Fix phased restart errors related to nio4r gem when using the Puma control server ([#2516])
* Add `#string` method to `Puma::NullIO` ([#2520])
* Fix binding via Rack handler to IPv6 addresses ([#2521])
* Require rack/common_logger explicitly if :verbose is true ([#2547])
Copy link
Member

Choose a reason for hiding this comment

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

whoops good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ssl waiting-for-changes Waiting on changes from the requestor waiting-for-review Waiting on review from anyone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants