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 // Remove acquired locks on exit
/* istanbul ignore next */ /* istanbul ignore next */
onExit(() => { let cleanupInitialized = false;
for (const file in locks) { function ensureCleanup() {
const options = locks[file].options; if (cleanupInitialized) {
return;
try { options.fs.rmdirSync(getLockFile(file, options)); } catch (e) { /* Empty */ }
} }
}); 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) => { module.exports.lock = async (file, options) => {
ensureCleanup();
const release = await toPromise(lock)(file, options); const release = await toPromise(lock)(file, options);
return toPromise(release); return toPromise(release);
} }