Live data from Hacker News

Tracking down the 16-year-old WAL-reset SQLite bug

tailscale.com

221–230 of 263 posts

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#221
post #212
post #182

It says a lot about sqlite that a bug becomes front-page news on HN. I'm impressed that Tailscale took this seriously enough to engage with a commercial support contract. I'd love to work for a company that cared so much about correctness.

Indeed, SQLite has got to be one of the best tested pieces of software with famously 100% test coverage. https://sqlite.org/testing.html It's amazing that a bug could exist for 16 years but it is sobering.

I think FoundationDB has that crown. https://antithesis.com/company/about/

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#222

Earlier quoted context omitted.

Not only are they funding open source, they are actively allowing users to host their own control plane via headscale which is a libre implementation of the tailscale control protocol and developed by an engineer who works for Tailscale by day. This instantly made me trust and like them, even if at first I was cautious because I naturally mistrust anything that gets a lot of hype. I've been running headscale on NixOS…

Important features like App Connectors won't work with HeadScale. Unfortunately, HeadScale is not a drop in replacement for TailScale. Most people don't realize this until they start self hosting. Due to this, I had to migrate from Tailscale to NetBird, which is completely open source. https://avilpage.com/2026/06/moving-from-tailscale-to-netbir...

Is this because HS hasn't implemented it yet (which is on the community), or because Tailscale does something to prevent them from working specifically?

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#223
post #123
post #67

Earlier quoted context omitted.

With a desktop its usually possible from the network setting GUI? Worked like that last time I needed to use a VPN for access to a corporate network.

Based on the experience that I (and other coworkers, including on other distros) had, whatever configurations our VPN needed did not seem to work out of the box on network manager.

A lot of this is just weird Linux on the desktop weirdness.

On Windows and Mac, VPN config is usually just installing a client, signing in, and then it all basically works. Sometimes you don't even need the client and can set it up in settings.

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#224

Earlier quoted context omitted.

Y? What's wrong with providing username/password authentication

Being an identity provider for anything important is the freaking worst. Exposes you to a million problems. You need human support for login problems and lost MFA tokens, and you are an attack magnet.

Which is why you want magic links.

Don't be the identity provider, have the email host be the identity provider (which it is anyway if you have a forgot password prompt).

Agreed 100% that nobody should still be using passwords in 2026 though.

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#225
> Nobody wanted us to spend six months looking for bugs in SQLite

Most companies wouldn't. Instead, they'd fire the weirdo that came up with the idea of using some weird db, and switch to Postgres like God intended.

I'm not saying either is right, this is not a criticism of Tailscale and their approach, paying the Sqlite maintainers to fix a real bug is commendable, but it certainly doesn't inspire confidence in the "Sqlite in production" hype train.

While Sqlite is indeed boring technology for single-user SQL DBs, for traditional CRUD and network services, Postgres seems to be a much better trodden and much safer path.

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#228
post #209
post #195

Earlier quoted context omitted.

> The bug only affects databases in WAL mode when there are two or more database connections open on the same file, in separate threads or processes To be honest, I'm surprised that someone using SQLite would try to access it directly from multiple threads or processes without fear of data racing.

> Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however. https://sqlite.org/faq.html#q5 One writer, multiple readers is a specifically supported way of using SQLite. Why should you be worried if it is used as designed?

> Why should you be worried if it is used as designed?

Well this whole article is about a company discovering a catastrophic corruption bug even though they were using it as designed.

I think the lesson is that if you're ever actually worried about concurrency then just don't use sqlite. We can see here that concurrency is hard and the bugs are old and deep.

Re: Tracking down the 16-year-old WAL-reset SQLite bug

#230
>"...and then we discovered an unexpected clue.

We wanted a way to restore service that didn’t involve rolling back to the last known-good backup (which would lose a lot of data) or repairing the known-corrupted database (which was potentially risky). To do this, we built a

transaction logging pipeline.

We streamed every SQL statement that modified the database to a separate log file. Because SQLite is a single-writer database with serializable transactions, our transaction history was completely linear and

deterministic.

(This wouldn’t be true in a multi-writer database like Postgres or MySQL.) Replaying those transactions against the latest known-good backup should restore the database to its most recent state, safely bypassing the corruption.

[...] This pipeline worked, but then it did something even better: it gave us a clue.

[...] To understand what was happening during these faulty checkpoints, the SQLite developers created a new debugging tool for the virtual filesystem layer.

[...] To help diagnose our problem, the SQLite developers created a wrapper around the virtual filesystem that

writes additional tracing information and logs

about changes to the database.

[...] After our next corruption incident, the additional logs from the new tmstmpvfs shim allowed the SQLite developers to find and fix the bug:

a rare data race

in the SQLite source code between a checkpoint and a write transaction."

Great article!

Software Engineering lessons (that repeat in this article!): So called "Heisenbugs" (bugs that make it past developer test harnesses and a company's Quality Assurance (QA) team) that show up post-deployment intermittently and can't be reproduced locally, occur because one or more of the following factors:

1) The lack of Determinism in a software process or processes.

2) The lack of appropriate logging.

3) The lack of the ability to replay a software process, step by exact step, state by exact state, as it has occurred in the field (occurs as an effect of #1 and/or #2).

4) Multi-threaded code; i.e., multiple threads giving rise to race conditions or other very specific intermittent combinatorial/permutational conditions caused by multiple threads and specific sections of code, which due to very large numbers of permutational timing possibilities, were not or could not be exactly tested for in development...

Anyway, great article! A must-read for any Sr. Software Engineer, or any developer that wrestles with hard-to-find-and-fix bugs in the field...

Post reply on HN