rm: cleanup from filestore (#5233)

This commit is contained in:
naman-bruno
2025-07-31 22:30:51 +05:30
committed by GitHub
parent ec51ebba45
commit 81b5e3c539

View File

@@ -31,54 +31,10 @@ export const stringifyRequest = (requestObj: ParsedRequest, options: StringifyOp
};
let globalWorkerInstance: BruParserWorker | null = null;
let cleanupHandlersRegistered = false;
const getWorkerInstance = (): BruParserWorker => {
if (!globalWorkerInstance) {
globalWorkerInstance = new BruParserWorker();
if (!cleanupHandlersRegistered) {
const cleanup = async () => {
if (globalWorkerInstance) {
await globalWorkerInstance.cleanup();
globalWorkerInstance = null;
}
};
// Handle various exit scenarios
process.on('exit', () => {
// Note: async operations won't work in 'exit' event
// We handle termination in other events
});
// Only register signal handlers in the main thread, not in worker threads
// This prevents conflicts and SIGABRT during collection run cancellation
if (!process.env.WORKER_THREAD && typeof process.send === 'undefined') {
process.on('SIGINT', async () => {
await cleanup();
process.exit(0);
});
process.on('SIGTERM', async () => {
await cleanup();
process.exit(0);
});
process.on('uncaughtException', async (error: Error) => {
console.error('Uncaught Exception:', error);
await cleanup();
process.exit(1);
});
process.on('unhandledRejection', async (reason: unknown) => {
console.error('Unhandled Rejection:', reason);
await cleanup();
process.exit(1);
});
}
cleanupHandlersRegistered = true;
}
}
return globalWorkerInstance;
};