Skip to content

newQueue closes the shared *sql.DB on initTable failure, breaking all other queues #8

Description

@fahimfaisaal

Summary

newQueue closes the shared database connection when initTable fails, tearing down every other queue created from the same manager.

Root cause

queue.go:34-37:

if err := q.initTable(); err != nil {
    db.Close()          // <-- db is shared across all queues
    return nil, fmt.Errorf("failed to initialize table: %w", err)
}

The *sql.DB is owned by the queues manager (queues.go) and shared by every Queue/PriorityQueue. A single failed NewQueue/NewPriorityQueue closes the connection for all of them.

Impact

Medium. One bad table name or transient error during NewQueue silently breaks unrelated, already-working queues on the same manager. The manager's own Close() is the only thing that should close the DB.

Possible fix

Remove the db.Close() call; let the manager own the connection lifecycle:

if err := q.initTable(); err != nil {
    return nil, fmt.Errorf("failed to initialize table: %w", err)
}

The same shared-DB assumption should be double-checked in newPriorityQueue's error paths (priority_queue.go:17-33), which correctly do not close the DB today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions