Skip to content
Browse files

Merge pull request #113 from mschulkind/master.

Proper connected status tracking to avoid deadlocks
  • Loading branch information...
2 parents 38ca0f2 + cfc6b1b commit c41bc94ea6e6eebb718428d74d22c84b6d2513a4 @pietern pietern committed May 4, 2011
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/redis/connection/synchrony.rb
View
12 lib/redis/connection/synchrony.rb
@@ -10,13 +10,19 @@ class RedisClient < EventMachine::Connection
def post_init
@req = nil
+ @connected = false
@reader = ::Hiredis::Reader.new
end
def connection_completed
+ @connected = true
succeed
end
+ def connected?
+ @connected
+ end
+
def receive_data(data)
@reader.feed(data)
@@ -39,6 +45,7 @@ def send(data)
end
def unbind
+ @connected = false
if @req
@req.fail [:error, Errno::ECONNRESET]
@req = nil
@@ -53,12 +60,11 @@ class Synchrony
def initialize
@timeout = 5_000_000
- @state = :disconnected
@connection = nil
end
def connected?
- @state == :connected
+ @connection && @connection.connected?
end
def timeout=(usecs)
@@ -79,7 +85,6 @@ def connect_unix(path, timeout)
end
def disconnect
- @state = :disconnected
@connection.close_connection
@connection = nil
end
@@ -105,7 +110,6 @@ def read
def setup_connect_callbacks(conn, f)
conn.callback do
@connection = conn
- @state = :connected
f.resume conn
end

0 comments on commit c41bc94

Please sign in to comment.
Something went wrong with that request. Please try again.