Skip to content

fix(redis): repair a damaged append-only file before Redis starts - #3531

Merged
vpetersson merged 2 commits into
masterfrom
fix/redis-aof-recovery
Nov 29, 2026
Merged

vpetersson merged 2 commits into
masterfrom
fix/redis-aof-recovery

Conversation

@vpetersson-bot

Copy link
Copy Markdown
Contributor

Issues Fixed

Fixes #3529

Description

When the AOF's incr file has a bad record in the middle (for example after a power cut or a failing card), Redis exits at startup with Bad file format reading the append only file. restart: always restarts it straight into the same failure, so the player loses its Celery broker, Channels layer and viewer command bus until someone repairs the file by hand.

This adds docker/redis/entrypoint.sh as the Redis image's ENTRYPOINT. The CMD is unchanged. On every start the entrypoint:

  1. Runs redis-check-aof on the manifest. This takes milliseconds on an AOF this size, and a healthy or missing AOF is left untouched.
  2. If the AOF is damaged, runs redis-check-aof --fix. That truncates the file at the first bad record and keeps everything before it, including the telemetry device_id this image persists the AOF for.
  3. If the AOF still can't be repaired (for example, the base file is damaged), moves appendonlydir to appendonlydir.corrupt, keeping only the latest copy, and seeds a new AOF from dump.rdb if redis-check-rdb accepts it. This seeding matters: Redis 7+ with appendonly yes ignores dump.rdb when the AOF directory is missing, so moving the AOF aside alone would start an empty dataset. If no snapshot is usable, Redis starts empty.

redis-tools provides both check tools. It is already a dependency of redis-server in the runtime image and is now added to the test image so the new tests run in CI.

Testing

  • tests/test_redis_entrypoint.py drives the script against real on-disk layouts with the real check tools: healthy, mid-file corruption, unrepairable AOF with and without a snapshot, repeated failures, and a first boot with no data. Four of these tests fail with a pass-through entrypoint.
  • On a Pi 4 (arm64) and a Pi 2 (armhf), using each board's published anthias-redis image with this entrypoint mounted: a corrupted incr AOF makes the shipped image exit 1 with Bad file format. With the entrypoint, the AOF is repaired, Redis reaches Ready to accept connections, and the seeded device_id survives.

Checklist

  • I have performed a self-review of my own code.
  • New and existing unit tests pass locally and on CI with my changes.
  • I have done an end-to-end test for Raspberry Pi devices.
  • I have tested my changes for x86 devices.
  • I added a documentation for the changes I have made (when necessary).

🤖 Generated with Claude Code

- Redis exits at startup on a bad record mid-AOF, and `restart: always`
  loops it forever, taking celery, the splash page and the viewer
  command bus down with it
- New entrypoint checks the AOF on every start and runs
  `redis-check-aof --fix`, keeping everything before the bad record
- If the AOF cannot be repaired, move it aside and seed a new one from
  the last RDB snapshot (Redis ignores dump.rdb when the AOF directory
  is missing), else start empty
- Add redis-tools to the test image so the recovery tests run in CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
@vpetersson-bot
vpetersson-bot requested a review from a team as a code owner November 27, 2026 22:25
Copilot AI lite review requested due to automatic review settings November 27, 2026 22:25
@vpetersson-bot vpetersson-bot self-assigned this Nov 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 27, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

@sonarqubecloud

Copy link
Copy Markdown

@vpetersson
vpetersson merged commit 748919b into master Nov 29, 2026
9 checks passed
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.

Redis crash-loops forever on a corrupted AOF, taking celery, the splash page and viewer updates down with it

3 participants