Skip to content

Add database connection resilience to the indexer #34

@rustydb

Description

@rustydb

Priority: P1

Source

Senior Architect Code Review (2026-04-03)

Problem

The Rust indexer uses a single tokio_postgres client connection with no reconnection logic or connection pooling. If the database connection drops (network blip, Cloud SQL restart, maintenance window), the indexer crashes and requires a full container restart.

The current code spawns the connection task and logs errors but does not attempt recovery:

tokio::spawn(async move {
    if let Err(error) = connection.await {
        eprintln!("postgres connection error: {error}");
    }
});

Affected Files

  • apps/indexer/src/main.rs (Database struct)

Recommendation

Replace the bare tokio_postgres client with a connection pool such as deadpool-postgres or bb8-postgres. These handle:

  • Automatic reconnection on connection loss
  • Connection health checking
  • Configurable pool size for concurrent package pollers
  • Graceful degradation during database outages

Alternatively, wrap the existing client in a reconnection loop that detects connection failures and re-establishes the connection before retrying.

Acceptance Criteria

  • Indexer survives a temporary database outage without crashing
  • Connection is re-established automatically after a drop
  • Concurrent package pollers share a connection pool
  • Connection pool size is configurable via environment variable
  • Behavior is tested (at minimum, a reconnection scenario)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrustPull requests that update rust code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions