Skip to content

Commit 09a9338

Browse files
authored
Merge pull request #649 from quixoten/fix_write_to_socket
Fix #_write_to_socket in connection
2 parents 37ab904 + a760c90 commit 09a9338

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/redis/connection/ruby.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +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_READ_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
31-
NBIO_WRITE_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
3230
if RUBY_VERSION >= "1.9.3"
33-
NBIO_READ_EXCEPTIONS << IO::WaitReadable
34-
NBIO_WRITE_EXCEPTIONS << IO::WaitWritable
31+
NBIO_READ_EXCEPTIONS = [IO::WaitReadable]
32+
NBIO_WRITE_EXCEPTIONS = [IO::WaitWritable]
33+
else
34+
NBIO_READ_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
35+
NBIO_WRITE_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
3536
end
3637

3738
def initialize(*args)
@@ -104,14 +105,14 @@ def _write_to_socket(data)
104105
begin
105106
write_nonblock(data)
106107

107-
rescue *NBIO_READ_EXCEPTIONS
108-
if IO.select([self], nil, nil, @write_timeout)
108+
rescue *NBIO_WRITE_EXCEPTIONS
109+
if IO.select(nil, [self], nil, @write_timeout)
109110
retry
110111
else
111112
raise Redis::TimeoutError
112113
end
113-
rescue *NBIO_WRITE_EXCEPTIONS
114-
if IO.select(nil, [self], nil, @write_timeout)
114+
rescue *NBIO_READ_EXCEPTIONS
115+
if IO.select([self], nil, nil, @write_timeout)
115116
retry
116117
else
117118
raise Redis::TimeoutError
@@ -306,6 +307,7 @@ def self.connect(config)
306307
raise ArgumentError, "SSL incompatible with unix sockets" if config[:ssl]
307308
sock = UNIXSocket.connect(config[:path], config[:connect_timeout])
308309
elsif config[:scheme] == "rediss" || config[:ssl]
310+
raise ArgumentError, "This library does not support SSL on Ruby < 1.9" if RUBY_VERSION < "1.9.3"
309311
sock = SSLSocket.connect(config[:host], config[:port], config[:connect_timeout], config[:ssl_params])
310312
else
311313
sock = TCPSocket.connect(config[:host], config[:port], config[:connect_timeout])

0 commit comments

Comments
 (0)