Skip to content

Multiple SQLite Sources get overwritten and only last one is accessible #115

@Yax

Description

@Yax

When configuring multiple SQLite databases in dbhub.toml, all source_id values query the same physical database (the last one configured).

Configuration

dbhub.toml:

[[sources]]
id = "database_a"
dsn = "sqlite:///app/database_a.db"
readonly = true

[[sources]]
id = "database_b"
dsn = "sqlite:///app/database_b.db"
readonly = true

docker-compose.yml:

services:
  dbhub:
    image: bytebase/dbhub:latest
    working_dir: /app
    ports:
      - "8080:8080"
    volumes:
      - type: bind
        source: ./database_a.db
        target: /app/database_a.db
        read_only: true
      - type: bind
        source: ./database_b.db
        target: /app/database_b.db
        read_only: true
      - type: bind
        source: ./dbhub.toml
        target: /app/dbhub.toml
        read_only: true
    command:
      - --transport
      - http
      - --port
      - "8080"
      - --config
      - /app/dbhub.toml

Expected Behavior

  • source_id: "database_a" → queries database_a.db
  • source_id: "database_b" → queries database_b.db

Actual Behavior

  • Both source_ids query database_b.db (the last configured source)
  • Only one database file is opened (confirmed via lsof)
  • Both sources return identical tables despite files being different

Probably Cause

ConnectorRegistry.getConnectorForDSN() returns a singleton connector instance for SQLite:

static getConnectorForDSN(dsn) {
  for (const connector of _ConnectorRegistry.connectors.values()) {
    if (connector.dsnParser.isValidDSN(dsn)) {
      return connector;  // ← Same instance for all SQLite databases
    }
  }
}

When connectSource() loops through sources, it:

  1. Gets the same SQLite connector instance for both databases
  2. Calls connector.connect(actualDSN) which overwrites the previous connection
  3. Stores the same connector instance for both source_ids

Result: Both source_ids reference the same connector connected to only the last database.

Probable Fix

ConnectorRegistry should create a new connector instance per source, not return a singleton.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions