driverdan / node-XMLHttpRequest

XMLHttpRequest for node.js
http://thedanexperiment.com/2009/10/04/emulating-xmlhttprequest-in-node-js/
MIT License
416 stars 299 forks source link

Fix file collision when running in workers. #197

Open lpaolini opened 2 years ago

lpaolini commented 2 years ago

In XMLHttpRequest.js lines 479-480, two filenames are defined using process.pid as a unique key.

      var contentFile = ".node-xmlhttprequest-content-" + process.pid;
      var syncFile = ".node-xmlhttprequest-sync-" + process.pid;

However, when running in workers this is not enough, due to the fact that the process.pid is the same across workers. This causes a filename collision.

Appending a UUID to the key fixes the problem.

      var uniqueId = process.pid + "-" + uuid.v4();
      var contentFile = ".node-xmlhttprequest-content-" + uniqueId;
      var syncFile = ".node-xmlhttprequest-sync-" + uniqueId;