Skip to content

[node-core-library] Race condition in FileSystem.create*Link helpers #5654

@dmichon-msft

Description

@dmichon-msft

Summary

The FileSystem._handleLink and FileSystem._handleLinkAsync helpers have a race condition if the parent folder of the link to be created does not exist: two calls attempting to create the same link concurrently can collide and fail with EEXIST and bypass the options.alreadyExistBehavior handler, since the handler only happens for the initial attempt.

Repro steps

Call FileSystem.createHardlinkAsync twice concurrently with the same newLinkPath (either in the same process or separate processes), instructed to create the links in a folder that does not currently exist.

Expected result:
Call should succeed if using AlreadyExistsBehavior.Overwrite or AlreadyExistsBehavior.Ignore.

Actual result:
If timed exactly wrong, even with AlreadyExistsBehavior.Overwrite or AlreadyExistsBehavior.Ignore, it can still fail with EEXIST.

Details

The helpers should be reorganized to include the FileSystem.isExistError code path in the retry handler from FileSystem.isNotExistError.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
Package name: @rushstack/node-core-library
Package version? 5.20.1
Operating system? Linux
Would you consider contributing a PR? Yes
Node.js version (node -v)? 22.16.0

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Needs triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions