Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

RuntimeError: maximum recursion depth exceeded when attempting to subscribe to a Redis server that is down #179

Closed
wedamija opened this Issue · 2 comments

3 participants

@wedamija

I've got an issue that occurs when attempting to subscribe to a channel when a Redis server is down. To reproduce, assuming the Redis server is down:

cli = redis.Redis(host='localhost')
ps = cli.pubsub()
ps.subscribe('test')

Problem is here:

    def execute_command(self, *args, **kwargs):
        "Execute a publish/subscribe command"
        if self.connection is None:
            self.connection = self.connection_pool.get_connection(
                'pubsub',
                self.shard_hint
                )
        connection = self.connection
        try:
            connection.send_command(*args)
            return self.parse_response()
        except ConnectionError:
            connection.disconnect()
            # resubscribe to all channels and patterns before
            # resending the current command
            for channel in self.channels:
                self.subscribe(channel)
            for pattern in self.patterns:
                self.psubscribe(pattern)
            connection.send_command(*args)
            return self.parse_response()

Basically, if we're trying to subscribe here, we'll get a ConnectionError, disconnect and then try to re-subscribe to the channel, which starts a recursive loop. I suggest that if we detect that the command we're trying to send here is 'SUBSCRIBE' or 'PSUBSCRIBE' then we don't attempt to resubscribe to any channels, and instead just raise the exception.

Something like

        except ConnectionError:
            connection.disconnect()
            if args[0] in ('SUBSCRIBE', 'PSUBSCRIBE'):
                raise
@ovidiucp

I have a fix for it, check it out here:

#195

@wedamija

Awesome, can't wait for it to be included!

@knzm knzm referenced this issue from a commit in knzm/redis-py
@knzm knzm back-port part of 32256bb
Original commit log:

    manually reconnect the connection in the PubSub class. This avoids blowing out the stack. Fixes #179 and #195.
e7a38d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.