fs-write-stream-atomic icon indicating copy to clipboard operation
fs-write-stream-atomic copied to clipboard

Incorporate worker thread id in temporary filename

Open wbinnssmith opened this issue 5 years ago • 1 comments

What / Why

With the addition of Worker Threads [0] in Node, multiple concurrent threads could attempt to write to the same temporary filename, given they share the same process.pid, and could share the same invocation count as well. This incorporates the thread id, exposed from the worker_threads exports as threadId.

The "main" process does not have a threadId, so -1 is used as its id in that case, as well as in the case the worker_threads module isn't available, such as in older versions of node.

Test Plan

Added a test for normalizing the threadId.

References

[0] https://nodejs.org/api/worker_threads.html

cc @isaacs @aeschright @padmaia @devongovett @mischnic

wbinnssmith avatar May 18 '20 21:05 wbinnssmith

Looks like worker threads were marked as experimental through Node 11 and that the environments that Travis tests likely don't have them at all, or they're behind an experimental flag.

The environments should probably be updated to include newer versions of Node to exercise this behavior (and maybe drop unmaintained versions <= Node 8)

wbinnssmith avatar May 18 '20 21:05 wbinnssmith