Skip to content

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

Merged
OnFreund merged 2 commits into
Sendspin:mainfrom
kiwipaulrob:fix/atomic-settings-save
Oct 6, 2026
Merged

OnFreund merged 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.

@OnFreund
OnFreund merged commit 40d2b4d into Sendspin:main Oct 6, 2026
2 checks passed
@maximmaxim345 maximmaxim345 added the bugfix Fixes a bug label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants