Skip to content

fix: handle corrupt WAL files during replay without panic - #26556

Merged
praveen-influx merged 1 commit into
mainfrom
sgc/26549/corrupt_wal
Jun 24, 2025
Merged

praveen-influx merged 1 commit into
mainfrom
sgc/26549/corrupt_wal

Conversation

@stuartcarnie

@stuartcarnie stuartcarnie commented Jun 24, 2025 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a critical issue where InfluxDB3 would panic on startup when encountering corrupt or empty WAL files, typically after power outages or disk failures.

Issue

When WAL files become corrupted (e.g., truncated to 0 bytes during power loss), the server would panic with:

thread 'main' panicked at influxdb3_wal/src/serialize.rs:50:30:
range end index 8 out of range for slice of length 0

This prevented the server from starting, requiring manual intervention to remove corrupt files.

Now, the user will see a WARN log when encountering corrupt WAL files:

2025-06-24T07:19:41.278619Z  WARN influxdb3_wal::object_store: Skipping corrupt WAL file error=WAL file too small: expected at least 12 bytes, but got 0 bytes path=ingest/wal/00000000009.wal

The user can opt-out of this behaviour by specifying the --wal-replay-fail-on-error CLI argument.

Solution

  1. Added bounds checking in WAL deserialization:

    • New WalFileTooSmall error variant that clearly indicates expected vs actual file size
    • Validation ensures files have at least 12 bytes (8-byte identifier + 4-byte CRC32) before attempting to read
    • Graceful error handling instead of panic
  2. Made WAL replay behavior configurable:

    • New CLI flag --wal-replay-fail-on-error (env: INFLUXDB3_WAL_REPLAY_FAIL_ON_ERROR)
    • Default behaviour: skip corrupt files and continue
    • Optional strict mode: fail on any corrupt file
  3. Enhanced error handling in WAL replay:

    • Modified replay logic to handle corrupt files based on configuration
    • Clear error messages distinguish between different corruption types
    • Proper propagation of errors through the replay pipeline

Test plan

  • Added unit tests for empty WAL files
  • Added unit tests for truncated WAL files (< 12 bytes)
  • Added unit tests for files with only header but no data
  • Verified existing tests pass
  • Manual testing with corrupted WAL files

Closes #26549

Add bounds checking to prevent panic when WAL files are empty or
truncated. Introduces `--wal-replay-fail-on-error` flag to control
behavior when encountering corrupt WAL files during replay.

- Add WalFileTooSmall error for files missing required header bytes
- Validate minimum file size (12 bytes) before attempting
  deserialization
- Make WAL replay configurable: skip corrupt files by default or fail
  on error
- Add comprehensive tests for empty, truncated, and header-only files

Closes #26549
@stuartcarnie
stuartcarnie force-pushed the sgc/26549/corrupt_wal branch from a5a3732 to 4cc9c67 Compare June 24, 2025 07:38
@stuartcarnie stuartcarnie self-assigned this Jun 24, 2025
@stuartcarnie
stuartcarnie marked this pull request as ready for review June 24, 2025 07:39
@stuartcarnie
stuartcarnie requested a review from a team June 24, 2025 07:39

@praveen-influx praveen-influx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skipping corrupt WAL files looks like the right thing to do 💯 , it's nice to have an opt-out behavior as well ✅

I wonder how we ended up with the zero length files / partial writes - I was under the assumption we can never see partial writes on object store. If this can happen for WAL files, could this also happen on data (.parquet) files, catalog log files etc. WAL files are probably most frequently written files so the other ones are much less likely to run into this problem. It'd be good to understand whether it's possible to end up in similar situation for other files and address it in a separate issue.

@pauldix

pauldix commented Jun 24, 2025 •

Copy link
Copy Markdown
Member

I was under the assumption we can never see partial writes on object store.

From the reported issue my guess is they were using the file system backed object store, which doesn't have the same guarantees as a real object store. So it's possible to get the file created without data actually going into it.

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.

InfluxDB3 Core failed to initialized write buffer: error from wal: join error

3 participants