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

Trilogy::SSLError is raised when a vitess vtgate is shut down #125

Closed
brendar opened this issue Oct 4, 2023 · 2 comments · Fixed by #128
Closed

Trilogy::SSLError is raised when a vitess vtgate is shut down #125

brendar opened this issue Oct 4, 2023 · 2 comments · Fixed by #128

Comments

@brendar
Copy link
Contributor

brendar commented Oct 4, 2023

When using trilogy >= 2.5.0 with Vitess and connected to a vtgate (the proxy that mysql clients connect to), trilogy raises trilogy_query_recv: SSL Error: (null) (Trilogy::SSLError) when the vtgate shuts down and closes the connection on the server side. This issue did not occur in Trilogy v2.4.1, which raised trilogy_query_recv: TRILOGY_CLOSED_CONNECTION (Trilogy::QueryError).

This error makes it hard for clients to know whether they should reconnect and retry the query.

e.g. with 2.6.0

irb(main):001:0> vtgate_client = Trilogy.new(host: "127.0.0.1", port: 23306, ssl: true, ssl_mode: Trilogy::SSL_REQUIRED_NOVERIFY)
=> #<Trilogy:0x00007f855c19eb30 @connection_options={:host=>"127.0.0.1", :port=>23306, :ssl=>true, :ssl_mode=>3}>

# vtgate is stopped

irb(main):002:0> vtgate_client.query("SELECT 1")
(irb):2:in `query': trilogy_query_recv: SSL Error: (null) (Trilogy::SSLError)
	from (irb):2:in `<main>'
	from /opt/rubies/ruby-3.1.4-pshopify1/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /usr/local/bin/irb:25:in `load'
	from /usr/local/bin/irb:25:in `<main>'

mysql2 raises this as a Mysql2::Error::ConnectionError, e.g.

irb(main):002:0> mysql2_vtgate_client = Mysql2::Client.new(host: "127.0.0.1", port: 23306, ssl_mode: :required)
=>
#<Mysql2::Client:0x00007f275fcd7480

# vtgate is stopped

irb(main):003:0> mysql2_vtgate_client.query("SELECT 1")
/home/spin/.local/share/gem/ruby/3.1.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:151:in `_query': Lost connection to MySQL server during query (Mysql2::Error::ConnectionError)
	from /home/spin/.local/share/gem/ruby/3.1.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:151:in `block in query'
	from /home/spin/.local/share/gem/ruby/3.1.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:150:in `handle_interrupt'
	from /home/spin/.local/share/gem/ruby/3.1.0/gems/mysql2-0.5.5/lib/mysql2/client.rb:150:in `query'
	from (irb):3:in `<main>'
	from /opt/rubies/ruby-3.1.4-pshopify1/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /usr/local/bin/irb:25:in `load'
	from /usr/local/bin/irb:25:in `<main>'

Running a git bisect, it looks like this behavior was introduced in #112

If you're interested in reproducing locally, I've added an SSL-enabled vtgate to docker-compose.yml in this branch.

@jhawthorn
Copy link
Member

Thanks for the report and especially reproduction! We may have had the desired behaviour prior to #112, but that would have been due to a bug (two wrongs making a right 😅) and may not have been consistent (it relied on us attempting to read/write on that closed connection after we'd seen an error).

I've opened #128 which should fix this.

Also worth noting is that in Trilogy 2.6.0 TRILOGY_CLOSED_CONNECTION now has a proper error class Trilogy::EOFError instead of the generic Trilogy::QueryError, hope that helps 😊!

@brendar
Copy link
Contributor Author

brendar commented Oct 24, 2023

I can confirm that #128 resolves the issue. Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants