You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
storage/localfilesystem: saveLibraryEntry does not await util.writeFile, causing intermittent test/race on final rename #5966
saveLibraryEntry in packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/library.js does not return/await the promise from util.writeFile(), so it resolves before the write+rename to the final file path has completed.
util.writeFile() (.../localfilesystem/util.js) writes to a temp file <path>.$$$ first and only fs.rename()s it to the final path once the write+fsync completes. Because that promise is not returned from the .then() callback in saveLibraryEntry, callers can observe the library directory before the rename has happened.
Repro
This surfaces as an intermittent failure of test/unit/@node-red/runtime/lib/storage/localfilesystem/library_spec.js ("should return a newly saved library function"), more frequently reproducible under Node 24's I/O timing:
The test calls saveLibraryEntry then immediately lists the library directory; occasionally it observes the temp .$$$ file because the rename hasn't happened yet.
Fix
saveLibraryEntry: asyncfunction(type,path,meta,body){
...
returnfs.ensureDir(fspath.dirname(fn)).then(function(){returnutil.writeFile(fn,headers+body);// <-- return the promise});}
Environment
Observed on a fork's CI matrix, Node 24, but the bug is present in current node-red/node-redmain (confirmed via diff — this file is unmodified from upstream in the fork where it was found).
Activity
Wait for a library entry to be written before resolving the save