fix(cli): sped up exit shutdown handlers
Run session_shutdown extension handlers concurrently under the existing shutdown cap so /exit and /quit do not wait one full timeout per hanging extension. Fixes #2736
This commit is contained in:
@@ -543,7 +543,9 @@ export class ExtensionRunner {
|
||||
event.type === "session_before_tree"
|
||||
);
|
||||
}
|
||||
|
||||
#isSessionShutdownEvent(event: RunnerEmitEvent): event is Extract<RunnerEmitEvent, { type: "session_shutdown" }> {
|
||||
return event.type === "session_shutdown";
|
||||
}
|
||||
async #runHandlerWithTimeout<TEvent extends { type: string }, TResult>(
|
||||
handler: (event: TEvent, ctx: ExtensionContext) => Promise<TResult | undefined> | TResult | undefined,
|
||||
event: TEvent,
|
||||
@@ -588,6 +590,20 @@ export class ExtensionRunner {
|
||||
const ctx = this.createContext();
|
||||
let result: SessionBeforeEventResult | SessionCompactingResult | undefined;
|
||||
|
||||
if (this.#isSessionShutdownEvent(event)) {
|
||||
const timeoutMs = handlerTimeoutForEvent(event.type);
|
||||
const promises: Promise<unknown>[] = [];
|
||||
for (const ext of this.extensions) {
|
||||
const handlers = ext.handlers.get(event.type);
|
||||
if (!handlers || handlers.length === 0) continue;
|
||||
for (const handler of handlers) {
|
||||
promises.push(this.#runHandlerWithTimeout(handler, event, ctx, ext, timeoutMs));
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
return result as RunnerEmitResult<TEvent>;
|
||||
}
|
||||
|
||||
for (const ext of this.extensions) {
|
||||
const handlers = ext.handlers.get(event.type);
|
||||
if (!handlers || handlers.length === 0) continue;
|
||||
|
||||
Reference in New Issue
Block a user