Skip to content

bootstrap crashes with deadlock on macOS (fatal: all goroutines are asleep) #7

@gitcoder89431

Description

@gitcoder89431

Environment

  • macOS 15 (arm64 / Apple Silicon)
  • tuitube v0.1.1 darwin_arm64 release binary
  • mpv and yt-dlp installed via Homebrew

Steps to reproduce

# download release tarball, extract, move binary to PATH
tuitube bootstrap --catalog /path/to/catalog.db

What happens

merging catalog from /tmp/catalog.db...
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [select]:
database/sql.(*DB).conn(...)
...
github.com/gitcoder89431/tuitube/internal/db.(*DB).seedDemoPlaylists(...)
        internal/db/catalog.go:155
github.com/gitcoder89431/tuitube/internal/db.(*DB).MergeCatalogFull(...)
        internal/db/catalog.go:120

Root cause

In seedDemoPlaylists (internal/db/catalog.go), the code opens a cursor with db.conn.Query("SELECT name FROM cat.demo_playlists") and then — while that cursor is still open — issues additional queries inside the loop (QueryRow, Exec). The DB is configured with SetMaxOpenConns(1), so the second query can't acquire a connection while the first cursor holds the only one → deadlock.

Fix

Drain all rows from the cursor into a []string slice, close the cursor, then do the per-name queries:

// collect names first, then close cursor before issuing more queries
var names []string
for rows.Next() { ... names = append(names, name) }
rows.Close()

for _, name := range names {
    db.conn.QueryRow(...) // safe now, no open cursor
}

Expected

Bootstrap completes successfully and reports merged tracks/playlists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions