Skip to content

fix(generic): close the connection Migrate leaks on a fresh database - #37

Closed
cbalan wants to merge 1 commit into
masterfrom
claude/kine-cgo-sqlite-wal-checkpoint-659923
Closed

cbalan wants to merge 1 commit into
masterfrom
claude/kine-cgo-sqlite-wal-checkpoint-659923

Conversation

@cbalan

@cbalan cbalan commented Nov 9, 2026 •

Copy link
Copy Markdown

Cherry-pick of upstream k3s-io/kine@f805442 ("Fix connection leak in Migrate", Tom Wieczorek), with a conventional, non-fork scope so it passes the master fork policy.

Why

Generic.Migrate opened both COUNT(*) rows up front and returned after the first Scan failed. On any database without the legacy key_value table, the second row was never read and kept its connection checked out forever. When the SQLite statement cache is on (_stmt_cache_size, part of the default DSN on the release lines), that leaked statement also holds a read transaction on the startup snapshot, so every post-compaction PRAGMA wal_checkpoint(FULL) waits out the full 30 s busy timeout. That is the TestCompact failure on release/vcluster/v0.17.2 (ENGCP-1950, blocking #35).

Changes

  • pkg/drivers/generic/generic.go: query kine only after the key_value row has been scanned and warrants it.
  • pkg/drivers/sqlite/sqlite_test.go (new, cgo only): TestMigrateReleasesItsConnections opens the SQLite backend with a 1-connection pool and checks the DB is still usable after Migrate.

Backport adaptations for master: Migrate keeps plain SQL strings (master predates query.New), and the test uses master's default DSN parameters.

Testing

  • TestMigrateReleasesItsConnections fails without the fix (pool exhausted, 5 s timeout) and passes with it.
  • CGO_ENABLED=1 go test ./pkg/drivers/... ./pkg/logstructured/... passes; CGO_ENABLED=0 go build ./... passes.

A backport to release/vcluster/v0.17.2 as fix(fork): ... follows in a separate PR.

Refs: ENGCP-1950

🤖 Generated with Claude Code

@cbalan
cbalan force-pushed the claude/kine-cgo-sqlite-wal-checkpoint-659923 branch from f24fd2f to 708001d Compare November 9, 2026 16:30
@cbalan cbalan changed the title Fix connection leak in Migrate (cherry-pick k3s-io/kine@f8054429) fix(generic): close the connection Migrate leaks on a fresh database Nov 9, 2026
@cbalan
cbalan force-pushed the claude/kine-cgo-sqlite-wal-checkpoint-659923 branch from 708001d to a29245f Compare November 9, 2026 16:34
@cbalan cbalan closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants