Repository navigation
Recover from a zeroed config.json instead of failing every start - #47
Merged
Merged
Conversation
A lab VM was powered off about 28 seconds after a self-update rewrote config.json. writeFile renamed the temp file without flushing it, so NTFS kept the new length and lost the data: config.json came back as 651 zero bytes. Every service start then died on "invalid character '\x00'", and the MSI's setup step hit the same error, so a reinstall failed with 1603 and rolled back to no service at all. - writeFile flushes the temp file before the rename, as the update package's writeFileSync already did. This covers the key and certificate too. - Load falls back to config.json.prev when config.json cannot be parsed. The service start, setup, renew and update paths log the recovery, keep the damaged file as config.json.damaged and write config.json back. update repairs before update.Arm copies config.json over .prev. - With no usable .prev, the error says to delete config.json and run setup again with --server. Proven on the VM: the fixed MSI installed over the zeroed file, logged the recovery, kept host 211 and its certificate, and polled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A Windows host was powered off about 28 seconds after a self-update (0.1.19 to 0.1.20) rewrote
config.json. The file came back as 651 zero bytes. Every service start failed withenroll: config.json: invalid character '\x00'. The MSI reinstall failed too (1722, then 1603), because its setup step reads the same file. The rollback left no service.Cause
enroll.writeFilewrote a temp file and renamed it without a flush. NTFS committed the rename and the length before the data.Fix
writeFileflushes before the rename, asupdate.writeFileSyncalready does. This also coverskey.pemandcert.pem.Loadfalls back toconfig.json.prevwhenconfig.jsoncannot be parsed. The service start, setup,renewandupdatepaths log the recovery, keep the damaged file asconfig.json.damaged, and writeconfig.jsonback.updaterepairs beforeupdate.Armcopiesconfig.jsonover.prev..prev, the error says to deleteconfig.jsonand run setup again with--server.Known limit:
.previs the copy from the last update. If the host enrolled again after that update,.prevcan name an older host id. The log line says to check the server URL and host id.Verification
go vet(linux, windows, darwin) andgo test ./...pass.ok.🤖 Generated with Claude Code