A linter I really recommend you to use if you're doing SQL in Golang
The sqlclosecheck linter catches unclosed sql.Rows and sql.Stmt objects in Go code, which otherwise can cause deadlocks or inefficient disk use in databases like SQLite. A short example shows it flagging a missing rows.Close() and passing once defer rows.Close() is added. It can be added to CI as a GitHub Actions step via go vet -vettool, or enabled in golangci-lint through .golangci.yaml, and is recommended as a standard CI check.
Related posts
- Something you probably want to know about if you're using SQLite in Golang
Turso mediumAdeptIn SQLite's WAL mode, an unclosed Go database/sql rows object keeps a read transaction open, which stops checkpoints from moving changes from the WAL file into the main database file. The WAL then grows without bound until the process restarts. In the example, leaking rows left a 42 MB WAL and a 4.1 kB main file, versus about 406 kB and 4.1 MB normally, and a manual PRAGMA wal_checkpoint did not fix it. Always close the results of Query and QueryContext; the same leak also blocks VACUUM.
- How to get your database access code deadlocked in Golang
Turso mediumAdeptIn Go's database/sql, failing to close a Rows result can deadlock the program when a loop over query results returns early on error. Rows holds a reader lock on the underlying sql.Conn until it is fully iterated or explicitly closed, so a deferred conn.Close() waits forever for the writer lock. The same leak hits plain db.QueryContext through the connection pool, which is easy to reproduce with SetMaxOpenConns(1). The happy path works fine, so the bug hides in under-tested error paths; the fix is to always defer rows.Close().
- How we used Quint to find over 10 bugs in SQLite while hardening Turso
Turso mediumAdeptModeling individual SQLite C API contracts in Quint, generating small traces, and replaying them as C programs against real SQLite uncovered more than 10 SQLite bugs while also validating Turso's compatible C API. Rather than specifying the whole database, each documented contract was modeled with only the state it needs, so a divergence points either to a model error or to a real bug. One example: sqlite3_deserialize() crashed instead of returning SQLITE_BUSY during an active read transaction. Other findings include wrong results from EXISTS-to-join and UPDATE planning optimizations, xfer optimization bypassing type and CHECK constraints, and mutex alignment undefined behaviour.
- Data needs its DevOps moment
Render mediumAdept
Data pipelines should be treated like any other production service: defined as code in the producing team's repo, with portable SQL logic tested in CI, and run 24x7 against SLOs for lag, freshness and completeness. A SQLFlow pipeline on Render shows the idea. It aggregates the Bluesky Jetstream firehose into one-minute tumbling windows per language before storing anything, which reduced 15 million posts to 6,577 Postgres rows and runs in a 512 MB instance. Render's default memory charts exposed two leaks that tests missed. DuckDB never freed deleted rows from indexed tables after a checkpoint, and the DuckDB Postgres extension copied key columns on every upsert. Fixing these led to a native pgx sink and a 30-minute soak test before each release.
- We’re All Just Looking for Connection
Slack Engineering mediumAdeptSpikes of EOFError on SQL queries in Quip's Python backend (which also powers Slack canvas) traced back to connection-state checks that only tracked closes initiated by the application. AWS's database proxy began closing connections after 24 hours, and because asyncio's StreamWriter.is_closing() doesn't reflect a peer-initiated FIN (a socket in CLOSE_WAIT can still be read), the code never reconnected before issuing queries. Instrumenting the drift between the connected flag and the actual closed state surfaced six more bugs, including websocket false negatives, stale HTTP pool clients and missed Redis cleanup. Fixing them nearly eliminated the errors and unblocked a stalled migration from a custom runtime to asyncio, where an overloaded RPC peer closing pooled connections had caused hanging PDF exports.