Version / branch / commit
main at 097c2652cba22d929c598347aacc6f95591c9031
OS and environment
Static persistence review; applies on all supported platforms.
Steps to reproduce
- Run a daemon status reader concurrently with daemon startup/status publication.
- Arrange for the reader to open the status file after truncation but before
os.WriteFile completes, or interrupt the process after truncation.
- Observe empty/partial JSON, or loss of the previous valid status file.
Relevant code: internal/daemon/server.go:200-214.
writeStatusFile calls os.WriteFile directly on the final path. os.WriteFile truncates the existing file before writing the replacement.
Expected behavior
Readers should observe either the previous complete status or the new complete status. A failed/interrupted update should not destroy the previous valid document.
Actual behavior
Concurrent readers can observe invalid JSON, and interruption after truncation can leave the status file empty or partial.
Suggested fix and regression test
Write to a unique same-directory temporary file, sync/close it, atomically rename it over the final path, and sync the parent directory where supported.
Add a test with a coordinated reader during publication and fault injection before rename; assert readers never observe partial JSON and the old document survives failed publication.
Reported by PierrunoYT from a full codebase audit.
Version / branch / commit
mainat097c2652cba22d929c598347aacc6f95591c9031OS and environment
Static persistence review; applies on all supported platforms.
Steps to reproduce
os.WriteFilecompletes, or interrupt the process after truncation.Relevant code:
internal/daemon/server.go:200-214.writeStatusFilecallsos.WriteFiledirectly on the final path.os.WriteFiletruncates the existing file before writing the replacement.Expected behavior
Readers should observe either the previous complete status or the new complete status. A failed/interrupted update should not destroy the previous valid document.
Actual behavior
Concurrent readers can observe invalid JSON, and interruption after truncation can leave the status file empty or partial.
Suggested fix and regression test
Write to a unique same-directory temporary file, sync/close it, atomically rename it over the final path, and sync the parent directory where supported.
Add a test with a coordinated reader during publication and fault injection before rename; assert readers never observe partial JSON and the old document survives failed publication.
Reported by PierrunoYT from a full codebase audit.