nodebuilder: preserve the existing config when config-update fails

Open
#5,436 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@guagucai is already working on this.

Since Nov 30, 2026.

  • #5437 by @guagucai — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

Read nodebuilder.UpdateConfig and SaveConfig, then trace the configuration file write path. Start with the focused filesystem regression tests described in the issue and run them against the production helper. Done means failed saves preserve the existing configuration, and replacement happens only after encoding, sync, and close succeed; the issue notes a patch is already prepared, so coordinate before taking it on.

Written by the indexing model from the issue text.

Description

external needs:triage
Celestia Node version

Source checkout of main at e0ad7f0e4520057e34c0b03c2f345cfd6b065dac.

OS

macOS, Darwin 25.5.0, arm64. This report concerns the local configuration-file write path, not a running network deployment.

Install tools

Source checkout; Go 1.26.10 for the focused filesystem regression tests.

Others

No running node is required. The failure is reproduced with a controlled encoder error after a partial file write, rather than by filling a real node's disk.

Steps to reproduce it
  1. Start with an existing config.toml containing custom configuration values.
  2. Inspect nodebuilder.UpdateConfig: after loading and merging the configuration, it calls removeConfig(cfgPath) before SaveConfig.
  3. Exercise the current SaveConfig write sequence with an encoder that writes a prefix and then returns an error. It opens the destination using os.Create, which truncates the existing file before encoding succeeds.
  4. Read the destination after the error. The previous contents have been replaced by the partial prefix. In UpdateConfig, an error opening the replacement after the preceding removal can instead leave the path absent.

A deterministic local regression uses an encoder callback in place of cfg.Encode while retaining the existing os.Create / encode sequence. This reproduces the failed-write behavior without requiring actual disk exhaustion. The proposed fix runs the same tests against the production file-writing helper.

Expected result

If saving fails before replacement, return the error and leave the existing configuration intact. Only publish the new configuration after encoding, file synchronization, and close have succeeded. Preserve existing file permission bits and clean up temporary files on returned errors.

Actual result

UpdateConfig removes the original before attempting the replacement. Independently, SaveConfig truncates the destination before encoding and ignores the deferred close error. An unsuccessful update can therefore leave the configuration missing or incomplete.

Relevant log output
=== RUN   TestSaveConfigAtomicReplacement
    destination changed before replacement: "complete replacement\n"
--- FAIL: TestSaveConfigAtomicReplacement
=== RUN   TestSaveConfigPreservesExistingFile/encode
    destination changed after failed save: "partial replacement"
--- FAIL: TestSaveConfigPreservesExistingFile/encode

These are excerpts from the controlled regression of the previous write sequence, not logs from a production node.

Is the node "stuck"? Has it stopped syncing?

Not applicable. This was investigated using source code and local filesystem tests; no live node was involved.

Notes

I have prepared a focused patch that removes the pre-save deletion, writes to a temporary file in the destination directory, checks encoding / sync / close errors, and renames the completed file over the destination. It preserves existing permission bits and existing symlinks to regular files. New files use mode 0600.

The focused filesystem tests pass with the patch. The complete nodebuilder package tests have not run successfully because dependencies are unavailable in the offline environment.

This proposal addresses configuration persistence reliability. It does not claim power-loss durability: synchronizing the parent directory after rename is outside the current patch. Please let me know whether this approach fits the project before I open a pull request.

Dominant language
Go
Stars
1k
Forks
1.1k
Avg merge
1d 22h
Merged PRs (30d)
55

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from celestiaorg/celestia-node

All issues in celestiaorg/celestia-node

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.