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

rescue IO::TimeoutError raised by Ruby since 3.2.0 on blocking reads/writes #968

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/dalli/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/dalli/protocol/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/dalli/protocol/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading