Skip to content

Catch all exceptions in health checks#6089

Merged
masenf merged 3 commits intomainfrom
masenf/catch-all-exceptions-in-health-check
Feb 12, 2026
Merged

Catch all exceptions in health checks#6089
masenf merged 3 commits intomainfrom
masenf/catch-all-exceptions-in-health-check

Conversation

@masenf
Copy link
Copy Markdown
Collaborator

@masenf masenf commented Jan 20, 2026

No description provided.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 20, 2026

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing masenf/catch-all-exceptions-in-health-check (3da46a5) with main (5d1d6db)

Open in CodSpeed

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Jan 20, 2026

Greptile Overview

Greptile Summary

Broadened exception handling in health check functions from specific exceptions (OperationalError, RedisError) to catching all exceptions, making the health checks more robust and ensuring they never crash.

  • Changed get_db_status() to catch Exception instead of sqlalchemy.exc.OperationalError
  • Changed get_redis_status() to catch Exception instead of RedisError
  • Removed unused RedisError import from get_redis_status() (still imported within get_redis() where needed)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes improve robustness by broadening exception handling in health check functions, which is appropriate since health checks should never crash. The existing tests remain valid and the removed import was redundant since RedisError is imported locally where it's actually used.
  • No files require special attention

Important Files Changed

Filename Overview
reflex/model.py Broadened exception handling in get_db_status() from OperationalError to all exceptions for more robust health checks
reflex/utils/prerequisites.py Removed unused RedisError import and broadened exception handling in get_redis_status() to catch all exceptions

Sequence Diagram

sequenceDiagram
    participant Client
    participant HealthEndpoint
    participant get_db_status
    participant get_redis_status
    participant Database
    participant Redis

    Client->>HealthEndpoint: GET /health
    HealthEndpoint->>get_db_status: check database
    get_db_status->>Database: SELECT 1
    alt Database responds
        Database-->>get_db_status: Success
        get_db_status-->>HealthEndpoint: {"db": true}
    else Any Exception occurs
        Database-->>get_db_status: Exception
        get_db_status-->>HealthEndpoint: {"db": false}
    end
    
    HealthEndpoint->>get_redis_status: check redis
    get_redis_status->>Redis: ping()
    alt Redis responds
        Redis-->>get_redis_status: Success
        get_redis_status-->>HealthEndpoint: {"redis": true}
    else Any Exception occurs
        Redis-->>get_redis_status: Exception
        get_redis_status-->>HealthEndpoint: {"redis": false}
    end
    
    HealthEndpoint-->>Client: {"status": bool, "db": bool, "redis": bool}
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Contributor

@Kastier1 Kastier1 left a comment

Choose a reason for hiding this comment

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

should we log what the exception is?

avoid spamming the "Database is not initialized, ..." message
@masenf masenf merged commit c3786b0 into main Feb 12, 2026
47 checks passed
@masenf masenf deleted the masenf/catch-all-exceptions-in-health-check branch February 12, 2026 18:42
benedikt-bartscher pushed a commit to benedikt-bartscher/reflex that referenced this pull request Mar 12, 2026
* Catch all exceptions in health checks

* log exceptions once in failed health check

avoid spamming the "Database is not initialized, ..." message
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.

3 participants