Skip to content

fix: improve error handling and logging for Redis stream connections - #1029

Open
wakonig wants to merge 1 commit into
mainfrom
fix/redis_retry_log
Open

fix: improve error handling and logging for Redis stream connections#1029
wakonig wants to merge 1 commit into
mainfrom
fix/redis_retry_log

Conversation

@wakonig

@wakonig wakonig commented Aug 21, 2026

Copy link
Copy Markdown
Member

Description

Streams were logging at 1 Hz if the connection got lost. While this is unlikely to happen in production, the development machines may not be able to connect to Atlas from the outside of PSI, leading to massive log file.
Here, I'm changing the logging behavior to log once on connection loss and once when the connection is re-established.
The pub sub was already only logging once but was lacking the recovery message, which I added now as well.

@wakonig wakonig self-assigned this Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ec_lib/redis_connector/managed_redis_connection.py 93.75% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@wakonig
wakonig marked this pull request as ready for review August 21, 2026 12:48
Copilot AI lite review requested due to automatic review settings August 21, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves Redis stream and pub/sub logging by suppressing repeated connection-loss messages and reporting recovery.

Changes:

  • Tracks stream connection failures.
  • Adds pub/sub recovery logging.
  • Adds outage and recovery tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Summary Findings
bec_lib/tests/test_managed_redis_connection.py Adds connection logging tests. No final comments.
bec_lib/bec_lib/redis_connector/managed_redis_connection.py Updates stream and pub/sub error handling. Two moderate issues remain involving failure-type preservation and validating successful reads before logging recovery.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bec_lib/bec_lib/redis_connector/managed_redis_connection.py Outdated
Comment thread bec_lib/bec_lib/redis_connector/managed_redis_connection.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

bec_lib/bec_lib/redis_connector/managed_redis_connection.py:560

  • Using or here discards normal_error whenever a from-start read also fails. With ACLs that deny different stream keys, the loop will log only the from-start topics forever and hide the normal subscription failure, even though the error text is intentionally topic-specific. Aggregate both errors (deduplicating identical connection errors) before applying the once-per-error logging logic.
            stream_error = from_start_error or normal_error

bec_lib/bec_lib/redis_connector/managed_redis_connection.py:568

  • If the last stream subscription is removed (or garbage-collected) after an error, this iteration can have no from_start_error or normal_error and perform no Redis read at all. The branch then reports that Redis reconnected even though connectivity was never verified, so a still-down server gets a false recovery log. Only clear the error and emit this message after a successful stream read.
            elif error is not None:
                error = None
                logger.info(f"{self.name} reconnected to redis ({self.host}:{self.port}).")

@wakonig
wakonig force-pushed the fix/redis_retry_log branch from 0dc162a to 3c66d96 Compare August 25, 2026 11:17
@wyzula-jan
wyzula-jan self-requested a review August 25, 2026 13:21
@wakonig
wakonig force-pushed the fix/redis_retry_log branch from 3c66d96 to 35c1261 Compare September 9, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants