From 5d52c437fdcd2c1d94de8f6f5675a1432fa49d74 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 30 Jun 2022 10:34:37 +0200 Subject: [PATCH] Handle OpenSSL v3 EOF errors Fix: https://github.com/redis/redis-rb/issues/1106 When Ruby is compiled against OpenSSL V3, if an SSL connection is closed without sending a `close_notify`, a `OpenSSL::SSL::SSLError` will be raised. --- lib/redis/client.rb | 2 +- lib/redis/connection/ruby.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/redis/client.rb b/lib/redis/client.rb index a988af37c..3e620faa9 100644 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -302,7 +302,7 @@ def io e2 = TimeoutError.new("Connection timed out") e2.set_backtrace(e1.backtrace) raise e2 - rescue Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EBADF, Errno::EINVAL => e + rescue Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EBADF, Errno::EINVAL, EOFError => e raise ConnectionError, "Connection lost (%s)" % [e.class.name.split("::").last] end diff --git a/lib/redis/connection/ruby.rb b/lib/redis/connection/ruby.rb index 81c81616c..f3740453b 100644 --- a/lib/redis/connection/ruby.rb +++ b/lib/redis/connection/ruby.rb @@ -384,6 +384,12 @@ def read format_reply(reply_type, line) rescue Errno::EAGAIN raise TimeoutError + rescue OpenSSL::SSL::SSLError => ssl_error + if ssl_error.message.match?(/SSL_read: unexpected eof while reading/i) + raise EOFError, ssl_error.message + else + raise + end end def format_reply(reply_type, line)