Skip to content

fix(settings): write settings file atomically via temp + rename - #285

Open
kiwipaulrob wants to merge 2 commits into
Sendspin:mainfrom
kiwipaulrob:fix/atomic-settings-save
Open

kiwipaulrob wants to merge 2 commits into
Sendspin:mainfrom
kiwipaulrob:fix/atomic-settings-save

Conversation

@kiwipaulrob

Copy link
Copy Markdown
Contributor

Problem

BaseSettings._save (sendspin/settings.py, shared by client and serve settings) rewrites the live JSON file in place with write_text. A kill mid-write truncates it, and on next start the JSONDecodeError handler logs a warning and silently falls back to defaults -- volume, name, interface and hooks all revert with no obvious cause.

Fix

Write-temp-then-rename: content goes to a .tmp sibling, is fsynced, then os.replace() swaps it into place atomically. A crash can now only leave the previous good file behind. Same OSError handling as before.

Verification

  • Full suite (pytest tests/, excluding serve + audio_devices): 123 passed
  • ruff check clean

Covers both ClientSettings and ServeSettings since they share _save.

This branch has not been deployed

No deployments
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.

1 participant