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.
Summary
newQueuecloses the shared database connection wheninitTablefails, tearing down every other queue created from the same manager.Root cause
queue.go:34-37:The
*sql.DBis owned by thequeuesmanager (queues.go) and shared by everyQueue/PriorityQueue. A single failedNewQueue/NewPriorityQueuecloses the connection for all of them.Impact
Medium. One bad table name or transient error during
NewQueuesilently breaks unrelated, already-working queues on the same manager. The manager's ownClose()is the only thing that should close the DB.Possible fix
Remove the
db.Close()call; let the manager own the connection lifecycle: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.