Skip to content

redis manager, verbose error logging #1479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/socketio/async_redis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ async def _publish(self, data):
self._redis_connect()
return await self.redis.publish(
self.channel, pickle.dumps(data))
except RedisError:
except RedisError as exc:
if retry:
self._get_logger().error('Cannot publish to redis... '
'retrying')
self._get_logger().error(
'Cannot publish to redis... '
'retrying',
extra={"redis_exception": str(exc)})
retry = False
else:
self._get_logger().error('Cannot publish to redis... '
'giving up')
self._get_logger().error(
'Cannot publish to redis... '
'giving up',
extra={"redis_exception": str(exc)})

break

async def _redis_listen_with_retries(self):
Expand All @@ -99,10 +104,11 @@ async def _redis_listen_with_retries(self):
retry_sleep = 1
async for message in self.pubsub.listen():
yield message
except RedisError:
except RedisError as exc:
self._get_logger().error('Cannot receive from redis... '
'retrying in '
'{} secs'.format(retry_sleep))
'{} secs'.format(retry_sleep),
extra={"redis_exception": str(exc)})
connect = True
await asyncio.sleep(retry_sleep)
retry_sleep *= 2
Expand Down
17 changes: 12 additions & 5 deletions src/socketio/redis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,18 @@ def _publish(self, data):
if not retry:
self._redis_connect()
return self.redis.publish(self.channel, pickle.dumps(data))
except redis.exceptions.RedisError:
except redis.exceptions.RedisError as exc:
if retry:
logger.error('Cannot publish to redis... retrying')
logger.error(
'Cannot publish to redis... retrying',
extra={"redis_exception": str(exc)}
)
retry = False
else:
logger.error('Cannot publish to redis... giving up')
logger.error(
'Cannot publish to redis... giving up',
extra={"redis_exception": str(exc)}
)
break

def _redis_listen_with_retries(self):
Expand All @@ -133,9 +139,10 @@ def _redis_listen_with_retries(self):
self.pubsub.subscribe(self.channel)
retry_sleep = 1
yield from self.pubsub.listen()
except redis.exceptions.RedisError:
except redis.exceptions.RedisError as exc:
logger.error('Cannot receive from redis... '
'retrying in {} secs'.format(retry_sleep))
'retrying in {} secs'.format(retry_sleep),
extra={"redis_exception": str(exc)})
connect = True
time.sleep(retry_sleep)
retry_sleep *= 2
Expand Down
Loading