fix(servicemanager): cancel shutdown timeouts after services stop
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/taskbuffer',
|
||||
version: '8.0.0',
|
||||
version: '8.0.1',
|
||||
description: 'A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.'
|
||||
}
|
||||
|
||||
@@ -158,12 +158,15 @@ export class ServiceManager {
|
||||
runningInLevel.map(async (name) => {
|
||||
const service = this.services.get(name)!;
|
||||
try {
|
||||
await Promise.race([
|
||||
service.stop(),
|
||||
plugins.smartdelay.delayFor(this.options.shutdownTimeoutMs).then(() => {
|
||||
throw new Error(`Timeout stopping service '${name}'`);
|
||||
}),
|
||||
]);
|
||||
const timeout = new plugins.smartdelay.Timeout(this.options.shutdownTimeoutMs);
|
||||
const timeoutPromise = timeout.promise.then(() => {
|
||||
throw new Error(`Timeout stopping service '${name}'`);
|
||||
});
|
||||
try {
|
||||
await Promise.race([service.stop(), timeoutPromise]);
|
||||
} finally {
|
||||
timeout.cancel();
|
||||
}
|
||||
} catch (err) {
|
||||
logger.log('warn', `${this.name}: error stopping '${name}': ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user