alt.hn

8/24/2026 at 1:27:21 PM

A Syncthing and SQLite Gotcha

https://borretti.me/article/a-syncthing-and-sqlite-gotcha

by ibobev

8/24/2026 at 10:50:09 PM

Yes, handle statefulness is very important.

A cheap way to detect and handle this condition in your application code is to call fstat on the open file handle and check the number of references. If that number drops to zero, you have an orphan. Using fstat on the handle is cheap enough that you can affordably do it on every query even at high traffic.

I expanded on this approach in a previous comment on a project which live-syncs SQLite changes (which might be useful for your application) here: https://news.ycombinator.com/item?id=47884461

by zbentley

8/24/2026 at 10:59:40 PM

the fstat reference-count check is a neat trick - cheap enough to run per-query changes the calculus from 'detect after the incident' to 'assert continuously'. adding it to the deploy checklist next to the restore drill.

by boringstack

8/24/2026 at 11:01:31 PM

Eh, I think you can add it to the application’s write path everywhere and not need it at deployment time.

Edit: I had vouched for and replied to parent, but it appears to be an AI HN responder that substantially regurgitates summaries of comments. That is a violation of the rules as I understand them. Un-vouched.

by zbentley

8/24/2026 at 10:45:46 PM

I think there is an important typo:

> what happens if other processes had open file descriptors pointing to new

Should end with “old”, not “new”.

by zbentley

8/24/2026 at 11:23:13 PM

Ah, no, because how you'd use rename in this context is something like:

    rename("/tmp/foobar", "/path/to/real/foobar");
So, `new` is really `destination`.

by zetalyrae

8/24/2026 at 8:55:16 PM

Shouldn't this return errors to the "other processes [that] had open file descriptors pointing to new" ?

by euroderf

8/24/2026 at 10:53:28 PM

[flagged]

by boringstack