Skip to content

Wait for a library entry to be written before resolving the save - #5975

Merged
knolleary merged 1 commit into
node-red:mainfrom
dlwhdgus0810:library-entry-write-promise
Oct 6, 2026
Merged

knolleary merged 1 commit into
node-red:mainfrom
dlwhdgus0810:library-entry-write-promise

Conversation

@dlwhdgus0810

Copy link
Copy Markdown
Contributor
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

Fixes #5966

saveLibraryEntry in localfilesystem/library.js called util.writeFile() without returning its promise. util.writeFile() writes to a temporary <path>.$$$ file and renames it to the final path when the write is done. The save therefore resolved before the rename, and a caller that listed the library right after saving could see the temporary file. This is the intermittent failure of "should return a newly saved library function" described in the issue.

The callback now returns the promise, so the save resolves once the file is in place.

How I checked it:

  • New test in library_spec.js: after saveLibraryEntry resolves, the final file exists and the .$$$ file does not.
    • Without the fix it failed in 5 out of 5 runs, and with the fix it passed in 5 out of 5.
    • It does not depend on timing, because the save resolves before any of the write's file I/O can finish.
  • The existing tests that wait 50 ms after saving still pass. I left those waits as they are.
  • The storage unit tests (test/unit/@node-red/runtime/lib/storage) pass: 81 passing, 2 pending.

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

saveLibraryEntry did not return the promise from util.writeFile, so it
resolved before the temporary file was renamed to its final path.
Callers that listed the library right after saving could see the
temporary .$$$ file instead.

Fixes node-red#5966
@knolleary
knolleary merged commit fb5e1a4 into node-red:main Oct 6, 2026
3 checks passed
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.

storage/localfilesystem: saveLibraryEntry does not await util.writeFile, causing intermittent test/race on final rename

2 participants