Skip to content

Commit cf9d7b3

Browse files
committed
handle IO::WaitWritable
1 parent d75708f commit cf9d7b3

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/redis/connection/ruby.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ module SocketMixin
2727
CRLF = "\r\n".freeze
2828

2929
# Exceptions raised during non-blocking I/O ops that require retrying the op
30-
NBIO_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
31-
NBIO_EXCEPTIONS << IO::WaitReadable if RUBY_VERSION >= "1.9.3"
30+
NBIO_READ_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
31+
NBIO_WRITE_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
32+
if RUBY_VERSION >= "1.9.3"
33+
NBIO_READ_EXCEPTIONS << IO::WaitReadable
34+
NBIO_WRITE_EXCEPTIONS << IO::WaitWritable
35+
end
3236

3337
def initialize(*args)
3438
super(*args)
@@ -78,12 +82,18 @@ def _read_from_socket(nbytes)
7882
begin
7983
read_nonblock(nbytes)
8084

81-
rescue *NBIO_EXCEPTIONS
85+
rescue *NBIO_READ_EXCEPTIONS
8286
if IO.select([self], nil, nil, @timeout)
8387
retry
8488
else
8589
raise Redis::TimeoutError
8690
end
91+
rescue *NBIO_WRITE_EXCEPTIONS
92+
if IO.select(nil, [self], nil, @timeout)
93+
retry
94+
else
95+
raise Redis::TimeoutError
96+
end
8797
end
8898

8999
rescue EOFError
@@ -94,7 +104,13 @@ def _write_to_socket(data)
94104
begin
95105
write_nonblock(data)
96106

97-
rescue *NBIO_EXCEPTIONS
107+
rescue *NBIO_READ_EXCEPTIONS
108+
if IO.select([self], nil, nil, @write_timeout)
109+
retry
110+
else
111+
raise Redis::TimeoutError
112+
end
113+
rescue *NBIO_WRITE_EXCEPTIONS
98114
if IO.select(nil, [self], nil, @write_timeout)
99115
retry
100116
else

test/ssl_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ def test_unverified_ssl_connection
2525
end
2626
end
2727

28+
def test_ssl_blocking
29+
RedisMock.start({}, ssl_server_opts("trusted")) do |port|
30+
redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
31+
assert_equal redis.set("boom", "a" * 10_000_000), "OK"
32+
end
33+
end
34+
2835
end
2936

3037
driver(:hiredis, :synchrony) do

0 commit comments

Comments
 (0)