Wrap logout save_all in a transaction (torn multi-table snapshot) #45

Closed
opened 2026-06-11 14:06:22 +00:00 by sickday · 0 comments
Owner

Problem

Persistence.save_all/1 writes 5 tables independently (position / skills / inventory / client_configs / music), each with its own rescue → {:error}. A crash or single-table failure mid-save leaves a torn snapshot — e.g. new position persisted but inventory not → on relog the player is at the new tile with the old backpack.

Fix

Wrap the logout/terminate save in a single Repo.transaction so it is all-or-nothing (SQLite + Postgres both support it). Keep per-subsystem error collection for diagnostics but roll back the whole set on any failure.

Acceptance

  • A failure in any one subsystem save rolls back the others (no partial persist on logout).

Refs: lib/black_lobster/game/entity/player/persistence.ex:save_all/1.

Part of the Security & Data-Integrity Hardening epic.

## Problem `Persistence.save_all/1` writes 5 tables independently (position / skills / inventory / client_configs / music), each with its own `rescue → {:error}`. A crash or single-table failure mid-save leaves a **torn snapshot** — e.g. new position persisted but inventory not → on relog the player is at the new tile with the old backpack. ## Fix Wrap the logout/terminate save in a single `Repo.transaction` so it is all-or-nothing (SQLite + Postgres both support it). Keep per-subsystem error collection for diagnostics but roll back the whole set on any failure. ## Acceptance - A failure in any one subsystem save rolls back the others (no partial persist on logout). Refs: `lib/black_lobster/game/entity/player/persistence.ex:save_all/1`. Part of the Security & Data-Integrity Hardening epic.
sickday added this to the v1 milestone 2026-06-11 14:11:16 +00:00
sickday self-assigned this 2026-06-11 14:11:26 +00:00
sickday added this to the v1 project 2026-06-11 14:11:48 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackLobster/Server#45
No description provided.