@@ -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
0 commit comments