Repository navigation
Conversation
Unique pid tmp names plus the existing withFileLock around both read-modify-write paths. Closes heygen-com#5333.
jrusso1020
left a comment
There was a problem hiding this comment.
Thanks for picking up #5333. The fix works: in a probe of 25 trials × 8 parallel node prefs.mjs record processes, this head kept every key and every user sighting, while main lost keys in about half the trials.
#5366 fixes the same issue with the same withFileLock approach, and we're going with that one, so I'd suggest closing this one as a duplicate. Here's why #5366 is ahead as submitted:
- It patches both copies of
prefs-store.mjs. This PR only changesskills/media-use/scripts/lib/prefs-store.mjs, soscripts/check-media-use-copy-parity.test.mjsfails ("standalone and CLI copies differ"). - It regenerates
skills-manifest.json. Here the media-use hash is stale, so the "Skills: manifest in sync" check would fail. - Its tests race separate processes behind a start barrier and fail on main every time. They also cover the user sighting ledger, re-reading after a held lock, and abandoned locks. With the fix reverted,
prefs-concurrency.test.mjsfailed on main in only 3 of 5 runs.
Smaller things that would also trip CI here: oxfmt wants prefs-store.mjs:144 wrapped and the two JSON.parse( blocks in the test collapsed. The comment at prefs-store.mjs:75 ("used to share…") is history narration, which the Comments check rejects.
Thanks again for the clear write-up and the repro.
— Rames
|
Closing this in favor of #5366, which covers the same race with the copy-parity and manifest updates called out in review. Thanks for the detailed feedback and for validating the fix. |
Summary
Parallel
prefs.mjs recordcalls shared one fixed tmp name, so the loser's rename died with ENOENT, and read-modify-write races dropped keys (#5333). Tmp names now carry the pid (astelemetry.mjsdoes), and both read-modify-write paths (recordProjectTier,recordUserSighting) run under the existingwithFileLockwith a re-read inside — including creating the parent dir first, which the lock itself needs.Test plan
skills/media-use/scripts/prefs-concurrency.test.mjs: the issue's exact 4-parallel repro (all exit 0, all 4 keys kept) + sequential accumulation. 2/2 pass; the parallel case fails on unpatched code (verified via stash).node --checkclean. Repo checks (check-comment-citations, ratchet, package suites) could not run here — nobunon this machine andnpm installisn't supported for workspace ops — CI will run them.Closes #5333