mirror of
https://github.com/hanzoai/mpc.git
synced 2026-10-30 19:45:28 +00:00
`go test ./...` here could not start a single test binary:
panic: sql: Register called twice for driver sqlite
database/sql.Register(...) database/sql/sql.go:63
modernc.org/sqlite.init.0() modernc.org/[email protected].0/sqlite.go:57
database/sql keys drivers by NAME and panics on a duplicate, so this is an
init-time process kill, not a test failure — mpcd the daemon died the same way.
mpcd links three SQLite-backed stores in one process. Two of them —
hanzoai/base's core and hanzoai/tasks' shard store — reach SQLite through
github.com/hanzoai/sqlite, which owns the "sqlite" name (delegating to
modernc.org/sqlite under !cgo and hanzoai/csqlite+SQLCipher under cgo, exactly
one registration either way). The third, luxfi/mpc's pkg/infra SQLiteMeta,
blank-imported modernc.org/sqlite directly. Two module paths, one driver name,
both init()s run.
Enumerated with `go list -deps` over the whole graph, the registrars of the name
"sqlite" were: modernc.org/sqlite (sqlite.go:57, driverName = "sqlite") and
github.com/hanzoai/sqlite (driver_cgo.go:43 under cgo, the modernc blank import
under !cgo). hanzoai/csqlite registers "sqlite3" and pgx/v5/stdlib registers
"pgx" — different names, no collision. The sole importer of modernc.org/sqlite
was github.com/luxfi/mpc/pkg/infra.
Fixed upstream where the offending import lives, not shimmed around here:
luxfi/mpc v1.17.16 routes SQLiteMeta through hanzoai/sqlite. Same shape as the
hanzoai/o11y fix — one package owns the driver, everyone else depends on it. No
driver was swapped and no build tag was added; the pure-Go/cgo split is
hanzoai/sqlite's own and is unchanged.
Deps move with it: luxfi/mpc v1.14.13 -> v1.17.16 and hanzoai/base v1.3.0 ->
v1.5.8 (v1.3.0's tag had also moved out from under go.sum, so a clean checkout
could not resolve it at all).
cmd/mpcd/sqlite_driver_test.go pins the invariant at the composition point that
actually broke. Its teeth are the import graph — the file compiles into package
main, so a second registrar panics during init and takes the whole test binary
down before any test runs. Verified red (panic, on luxfi/mpc v1.17.15 with every
other dep held fixed) then green, under CGO_ENABLED=0 and CGO_ENABLED=1.
go build ./... and go test ./... pass under both CGO settings.
Co-authored-by: Hanzo Dev <[email protected]>