Open connection to Navidrome's database prevents its WAL file from being cleaned up
Summary
While Spindle is running, Navidrome's navidrome.db-wal is not removed when Navidrome restarts. In my setup, it had reached 1.2 GB next to a 34 MB database.
Environment
- Spindle version: 0.4.1
- Navidrome version: 0.64.2
- Running in Docker, with Navidrome's data folder mounted into
spindle-backend NAVIDROME_DB_PATH=/nddata/navidrome.db
What I observed
navidrome.dbwas 34 MB andnavidrome.db-walwas 1.2 GB.- After stopping Navidrome, the WAL was still there at 1.2 GB.
fusershowed Spindle'snode dist/server.jsprocess still had both files open.- After stopping Spindle first and then Navidrome, the WAL was removed.
navidrome.dbstayed at 34 MB afterwards.
Likely cause
SQLite normally removes the WAL when the last connection closes. dist/db/navidrome-db.js opens the database read-only, and the connection appears to stay open while Spindle runs. With Spindle connected, Navidrome is never the last connection, so stopping it doesn't trigger that cleanup.
I haven't confirmed what made the WAL grow to 1.2 GB in the first place. It may have been a burst of writes, such as a library scan, rather than steady growth. Spindle's connection is read-only, and I saw no evidence of it writing to the database.
Steps to reproduce
- Run Navidrome and Spindle with the shared data folder.
- Let Navidrome's WAL grow, for example during a library scan.
- Stop Navidrome while Spindle is still running.
- Check that
navidrome.db-walis still there at the same size. - Stop Spindle, start Navidrome, then stop Navidrome again.
- Check that the WAL is gone.
Expected behavior
Spindle's read access shouldn't stop Navidrome's WAL from being cleaned up.
Possible fix
Open the Navidrome database only when it's needed and close it after each query or batch of queries, instead of keeping one connection open. This should let Navidrome be the last connection when it shuts down.
Workaround
docker stop spindle-backend- Restart Navidrome.
docker start spindle-backend
Fixed in v0.4.2.