-
Notifications
You must be signed in to change notification settings - Fork 89
Call getaddrinfo from Ruby
#139
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,23 @@ | |
|
|
||
| class Trilogy | ||
| def initialize(options = {}) | ||
| options = options.dup | ||
| options[:port] = options[:port].to_i if options[:port] | ||
| mysql_encoding = options[:encoding] || "utf8mb4" | ||
| encoding = Trilogy::Encoding.find(mysql_encoding) | ||
| charset = Trilogy::Encoding.charset(mysql_encoding) | ||
|
|
||
| if options[:host] | ||
| addrs = begin | ||
| Socket.getaddrinfo(options[:host], options[:port], :PF_UNSPEC, :SOCK_STREAM) | ||
| rescue SocketError | ||
| raise Trilogy::BaseConnectionError, "Couldn't resolve host: #{options[:host].inspect}" | ||
| end | ||
|
|
||
| addrs.sort_by!(&:first) # Priority to IPv4 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own understanding: does prioritizing IPv4 here match what happens when we were calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's a good question to which I don't have a proper answer. This PR is more proof of concept territory because I'm not very good at networking, so there might be a much simpler / better way to do this. The crux is really that I see processes stuck connecting to MySQL, and I highly suspect this is the cause. |
||
| options[:ip_address] = addrs.first[3] | ||
| end | ||
|
|
||
| @connection_options = options | ||
| @connected_host = nil | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,9 @@ def test_trilogy_connection_options | |
| ssl_mode: 4, | ||
| tls_min_version: 3, | ||
| } | ||
| assert_equal expected_connection_options, client.connection_options | ||
| actual_options = client.connection_options.dup | ||
| actual_options.delete(:ip_address) | ||
| assert_equal expected_connection_options, actual_options | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we assert |
||
| end | ||
|
|
||
| def test_trilogy_ping | ||
|
|
@@ -968,7 +970,7 @@ def test_connection_invalid_dns | |
| ex = assert_raises Trilogy::ConnectionError do | ||
| new_tcp_client(host: "mysql.invalid", port: 3306) | ||
| end | ||
| assert_equal "trilogy_connect - unable to connect to mysql.invalid:3306: TRILOGY_DNS_ERROR", ex.message | ||
| assert_includes ex.message, %{Couldn't resolve host: "mysql.invalid"} | ||
| end | ||
|
|
||
| def test_memsize | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.