Skip to content

file driver: replace device JSON files atomically - #162

Merged
eriknordmark merged 1 commit into
lf-edge:masterfrom
eriknordmark:atomic-json-write
Oct 19, 2026
Merged

eriknordmark merged 1 commit into
lf-edge:masterfrom
eriknordmark:atomic-json-write

Conversation

@eriknordmark

Copy link
Copy Markdown
Contributor

An attest request can fail with getDeviceOptions failed to unmarshal: unexpected end of JSON input (HTTP 500) when another request from the same device is rewriting options.json. Every attest request reads the options, and a nonce request rewrites them by truncating and then writing the file, so a concurrent read can see it empty. EVE retries later, but the delay was enough to fail evetest's two-minute config wait during onboarding.

Device JSON files are now written to a temporary file in the same directory and renamed over the target. The new OptionsReadDuringWriteIsComplete test reads 0 bytes against the old code and passes with the change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LvDPKeWJjD3ahjiJKF8b7f

A device's attest request can fail with "getDeviceOptions failed to
unmarshal: unexpected end of JSON input" when it arrives while another
request from the same device is rewriting options.json. Every attest
request reads the options, and a nonce request rewrites them by
truncating the file and then writing it, so a concurrent read can see an
empty file and the request gets an HTTP 500. EVE then waits for its next
retry, which delays onboarding.

Device JSON files (options, config, attest certs, storage keys) are now
written to a temporary file in the same directory and renamed over the
target, so readers see either the old or the new content.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LvDPKeWJjD3ahjiJKF8b7f
@eriknordmark
eriknordmark merged commit 0f849dc into lf-edge:master Oct 19, 2026
2 checks passed

@milan-zededa milan-zededa 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.

Sorry for a late review, LGTM.

@eriknordmark
eriknordmark deleted the atomic-json-write branch October 27, 2026 00:06
@milan-zededa milan-zededa mentioned this pull request Nov 12, 2026
4 of 7 tasks
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.

2 participants