diff --git a/lib/dalli/protocol.rb b/lib/dalli/protocol.rb index 1a7bac17..a54d10f6 100644 --- a/lib/dalli/protocol.rb +++ b/lib/dalli/protocol.rb @@ -4,5 +4,15 @@ module Dalli module Protocol # Preserved for backwards compatibility. Should be removed in 4.0 NOT_FOUND = ::Dalli::NOT_FOUND + + # Ruby 3.2 raises IO::TimeoutError on blocking reads/writes, but + # it is not defined in earlier Ruby versions. + require 'timeout' + TIMEOUT_ERRORS = + if defined?(IO::TimeoutError) + [Timeout::Error, IO::TimeoutError] + else + [Timeout::Error] + end end end diff --git a/lib/dalli/protocol/base.rb b/lib/dalli/protocol/base.rb index f5cffb6c..74274f80 100644 --- a/lib/dalli/protocol/base.rb +++ b/lib/dalli/protocol/base.rb @@ -106,7 +106,7 @@ def pipeline_next_responses end values - rescue SystemCallError, Timeout::Error, EOFError => e + rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e @connection_manager.error_on_request!(e) end diff --git a/lib/dalli/protocol/connection_manager.rb b/lib/dalli/protocol/connection_manager.rb index 0f5a01b6..27b514ce 100644 --- a/lib/dalli/protocol/connection_manager.rb +++ b/lib/dalli/protocol/connection_manager.rb @@ -150,19 +150,19 @@ def read_line data = @sock.gets("\r\n") error_on_request!('EOF in read_line') if data.nil? data - rescue SystemCallError, Timeout::Error, EOFError => e + rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e error_on_request!(e) end def read(count) @sock.readfull(count) - rescue SystemCallError, Timeout::Error, EOFError => e + rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e error_on_request!(e) end def write(bytes) @sock.write(bytes) - rescue SystemCallError, Timeout::Error => e + rescue SystemCallError, *TIMEOUT_ERRORS => e error_on_request!(e) end