From 42148cd3fc91e48bbb66edbd09028e2f2c82ee5e Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Mon, 7 Sep 2015 15:23:00 -0700 Subject: [PATCH] Fix Timeout interrupt handling on Ruby 2.3 Timeout::ExitException was removed in Ruby 2.3.0, 2.2.3, and 2.1.8 in favor of Timeout::Error, but only 2.1.x and 2.2.x have backward- compatibility aliases. --- lib/mysql2/client.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/mysql2/client.rb b/lib/mysql2/client.rb index 595cc8793..e19ba2c3f 100644 --- a/lib/mysql2/client.rb +++ b/lib/mysql2/client.rb @@ -82,8 +82,18 @@ def self.default_query_options if Thread.respond_to?(:handle_interrupt) require 'timeout' + # Timeout::ExitException was removed in Ruby 2.3.0, 2.2.3, and 2.1.8, + # but is present in earlier 2.1.x and 2.2.x, so we provide a shim. + # + # Set our own constant instead of modifying core ::Timeout. + TimeoutError = if defined?(::Timeout::ExitException) + ::Timeout::ExitException + else + ::Timeout::Error + end + def query(sql, options = {}) - Thread.handle_interrupt(::Timeout::ExitException => :never) do + Thread.handle_interrupt(TimeoutError => :never) do _query(sql, @query_options.merge(options)) end end