Skip to content

Commit

Permalink
Merge pull request redis#113 from mschulkind/master.
Browse files Browse the repository at this point in the history
Proper connected status tracking to avoid deadlocks
  • Loading branch information
pietern committed May 4, 2011
2 parents 38ca0f2 + cfc6b1b commit c41bc94
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/redis/connection/synchrony.rb
Expand Up @@ -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)

Expand All @@ -39,6 +45,7 @@ def send(data)
end

def unbind
@connected = false
if @req
@req.fail [:error, Errno::ECONNRESET]
@req = nil
Expand All @@ -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)
Expand All @@ -79,7 +85,6 @@ def connect_unix(path, timeout)
end

def disconnect
@state = :disconnected
@connection.close_connection
@connection = nil
end
Expand All @@ -105,7 +110,6 @@ def read
def setup_connect_callbacks(conn, f)
conn.callback do
@connection = conn
@state = :connected
f.resume conn
end

Expand Down

0 comments on commit c41bc94

Please sign in to comment.