fix: add fsync to writePEM before close (PILOT-138)#4
Conversation
The test writes a PEM block and reads it back immediately, pinning that writePEM produces a valid, readable file. This test will catch any future regression that removes or breaks the fsync behavior. Ref: PILOT-138
writePEM previously deferred f.Close() after pem.Encode with no intervening fsync. A process crash between Encode and the deferred Close would lose the newly-issued certificate, leaving a partial or missing PEM file on disk. Fix: call f.Sync() after pem.Encode to flush data to durable storage, then open and sync the parent directory so the directory entry itself is committed before writePEM returns. Closes PILOT-138
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
🦾 Matthew PR Check — #4 PILOT-138Status
CI Details
Mergeability
Recommendation🟡 Not ready to merge — codecov/patch check is failing. This is likely a coverage threshold delta (the added code may have reduced patch coverage). Review whether the test coverage is adequate or if the coverage threshold needs adjustment. Matthew PR Worker · 2026-05-28 15:25 UTC |
🦾 Matthew PR Explain — #4 PILOT-138What changedAdds durability guarantees to PEM certificate writes in the pilot-ca service. Files
Why
VerificationCI
Matthew PR Worker · 2026-05-28 15:25 UTC |
What failed
writePEMinpilot-ca/main.godeferredf.Close()afterpem.Encodewith no interveningfsync. A process crash between the Encode and the deferred Close would lose the newly-issued certificate, leaving a partial or missing PEM file on disk.Why this fix
f.Sync()afterpem.Encodeto flush data to durable storage.Sync()so the directory entry is committed beforewritePEMreturns.TestWritePEM_FsyncBeforeCloseregression test that writes a PEM block and reads it back immediately.Verification
Files changed
main.go— +9 lines inwritePEMzz_pilot_ca_test.go— +31 lines (new regression test)Closes PILOT-138