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

Binder - add/fix ssl 0.0.0.0/localhost logging, use ternary operator #2533

Merged
merged 1 commit into from
Jan 24, 2021

Conversation

MSP-Greg
Copy link
Member

Description

Binder - add/fix ssl 0.0.0.0/localhost logging, use tertiary

test_binder.rb - remove skips for:
test_correct_zero_port_ssl
test_logs_all_localhost_bindings_ssl

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 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.

@MSP-Greg
Copy link
Member Author

I believe that current code may show binds multiple times if there are multiple binds. Just pushed an update that should fix that...

io = add_ssl_listener uri.host, uri.port, ctx
logger.log "* Listening on #{str}"

@ios[ios_len..-1].each do |i|
Copy link
Member

Choose a reason for hiding this comment

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

Is the index necessary? are you just trying to reverse it? just use reverse_each

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not reverse. If there are multiple binds, I believe the current loop will print multiple entries?

Copy link
Member

Choose a reason for hiding this comment

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

I think I'm missing some context. What problem does this PR solve?

Copy link
Member Author

Choose a reason for hiding this comment

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

See two tests that had skips removed. Only pertains to '0.0.0.0' or 'localhost' binds

Copy link
Member

@cjlarose cjlarose Jan 24, 2021

Choose a reason for hiding this comment

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

I think I'm following this now. In this specific case, we want to print that we're listening on all newly-added entries to @ios.

In that case, I think it might be more straightforward for add_ssl_listener to return all instances of Puma::MiniSSL::Server it created.

ssl_servers = add_ssl_listener uri.host, uri.port, ctx
ssl_servers.each do |server|
  addr = loc_addr_str server
  ssl_qry = str[/\?.+\z/]
  logger.log "* #{log_msg} on ssl://#{addr}#{ssl_qry}"
end

Copy link
Member Author

@MSP-Greg MSP-Greg Jan 24, 2021

Choose a reason for hiding this comment

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

IDK.

I did just notice that ssl_qry = str[/\?.+\z/] can be moved out of the loop.

Note that add_ssl_listener currently returns the TCP server 'behind' the SSL server. The SSL server is added to @ios. That may not be needed, as I think it can also change if MiniSSL::Server does a better job of barking like a TCP server. I think I added MiniSSL::Server#closed? for that purpose in another PR.

A while ago, someone mentioned refactoring/rewriting BInder, so I haven't really looked at it. I've also got code for abstract unix sockets, and it runs with restart ok...

So, maybe wait on more serious Binder changes with Puma 6? Just a thought...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, happy to defer a refactor to a future PR 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the ssl_qry statement and also removed the next unless *Server === i statements, as with the @iOS length handling, they're no longer needed...

Copy link
Member

Choose a reason for hiding this comment

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

Both changes look good to me 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

@cjlarose Thanks for looking at it, @nateberkopec also...

@nateberkopec
Copy link
Member

That iterator looks weird otherwise seems fine

@MSP-Greg
Copy link
Member Author

Insert the following line at test_binder.rb:100:

STDOUT.puts '', @events.stdout.string

Run with the current PR, output is below, showing three IPv4 and 3 IPv6 addresses:

* Listening on http://127.0.0.1:35425
* Listening on http://[::1]:35425
* Listening on http://127.0.0.1:33875
* Listening on http://[::1]:33875
* Listening on http://127.0.0.1:34505
* Listening on http://[::1]:34505

Now, remove the 'array' part from binder.rb:171, and the output is below, showing the duplication:

* Listening on http://127.0.0.1:41103
* Listening on http://[::1]:41103
* Listening on http://127.0.0.1:41103
* Listening on http://[::1]:41103
* Listening on http://127.0.0.1:36667
* Listening on http://[::1]:36667
* Listening on http://127.0.0.1:41103
* Listening on http://[::1]:41103
* Listening on http://127.0.0.1:36667
* Listening on http://[::1]:36667
* Listening on http://127.0.0.1:41087
* Listening on http://[::1]:41087

lib/puma/binder.rb Outdated Show resolved Hide resolved
@dentarg
Copy link
Member

dentarg commented Jan 24, 2021

use tertiary

Heh, I didn't get it before I looked at the diff, I'm more used to the term "ternary operator"

test_binder.rb - remove skips for:
  test_correct_zero_port_ssl
  test_logs_all_localhost_bindings_ssl
@MSP-Greg MSP-Greg changed the title Binder - add/fix ssl 0.0.0.0/localhost logging, use tertiary Binder - add/fix ssl 0.0.0.0/localhost logging, use ternary operator Jan 24, 2021
@nateberkopec nateberkopec added the waiting-for-review Waiting on review from anyone label Jan 24, 2021
@nateberkopec nateberkopec merged commit ad92fc3 into puma:master Jan 24, 2021
@MSP-Greg MSP-Greg deleted the binder-ssl-localhost branch January 28, 2021 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting-for-review Waiting on review from anyone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants