fix: do not subscribe to SIGINT signal unless lock is acquired (#19978)

Subscription to SIGINT handler removes default handler.

Fixes #19418
This commit is contained in:
Andrey Lushnikov 2023-01-09 20:19:28 -08:00 committed by GitHub
parent 6022a4098f
commit 9943bcfcd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -382,15 +382,23 @@ function toPromise(method) {
// Remove acquired locks on exit
/* istanbul ignore next */
onExit(() => {
for (const file in locks) {
const options = locks[file].options;
try { options.fs.rmdirSync(getLockFile(file, options)); } catch (e) { /* Empty */ }
let cleanupInitialized = false;
function ensureCleanup() {
if (cleanupInitialized) {
return;
}
});
cleanupInitialized = true;
onExit(() => {
for (const file in locks) {
const options = locks[file].options;
try { options.fs.rmdirSync(getLockFile(file, options)); } catch (e) { /* Empty */ }
}
});
}
module.exports.lock = async (file, options) => {
ensureCleanup();
const release = await toPromise(lock)(file, options);
return toPromise(release);
}