Running that code leaves files with postfixes 1, 3, and 5 unremoved.
The problem in the code is that _garbageCollector loops through _removeObjects array, but at the same time calls to _cleanupCallback modify (splice) the array. As a result some of the _removeObjects functions will get removed before they have been called. (And _garbageCollector tries to invoke call for unexisting array indexes, but because of the empty catch block that is ignored.)
Test code to reproduce the problem:
const tmp = require('tmp');
tmp.fileSync({ dir: './', postfix: '.1' }); tmp.fileSync({ dir: './', postfix: '.2' }); tmp.fileSync({ dir: './', postfix: '.3' }); tmp.fileSync({ dir: './', postfix: '.4' }); tmp.fileSync({ dir: './', postfix: '.5' }); tmp.fileSync({ dir: './', postfix: '.6' });
Running that code leaves files with postfixes 1, 3, and 5 unremoved.
The problem in the code is that _garbageCollector loops through _removeObjects array, but at the same time calls to _cleanupCallback modify (splice) the array. As a result some of the _removeObjects functions will get removed before they have been called. (And _garbageCollector tries to invoke call for unexisting array indexes, but because of the empty catch block that is ignored.)