Release a message's hold when the response goes out, or when its listener failed

This commit is contained in:
2026-09-02 08:15:26 +02:00
parent 6cb186d38a
commit 3aadb64df8
7 changed files with 65 additions and 19 deletions
+10
View File
@@ -39,6 +39,8 @@ export class IncomingRequests {
private readonly session: Session;
private readonly smsIdFormat: SmsIdFormat;
private readonly systemId: string;
/** Identity, not a type guard: the rejected event carries the Sms back as an `unknown`. */
private readonly emitted = new WeakMap<object, () => void>();
private linkGeneration = 0;
constructor(options: IncomingRequestsOptions) {
@@ -111,6 +113,13 @@ export class IncomingRequests {
this.reassembler.clear();
}
/** A listener that rejected answered nothing and never will, so a shutdown may not wait for it. */
listenerRejected(sms: unknown): void {
if (typeof sms !== 'object' || sms === null) return;
this.emitted.get(sms)?.();
}
/** Waits out the messages the application still holds, and says how many it never answered. */
async drain(timeout: number, signal: AbortSignal | undefined): Promise<VoidResult> {
const unanswered = await this.held.idle(timeout, signal);
@@ -191,6 +200,7 @@ export class IncomingRequests {
});
this.held.hold(pduObjs);
this.emitted.set(sms, () => { this.held.release(pduObjs); });
// A message nobody took is not work a shutdown can wait for.
if (!this.session.emit('sms', sms)) this.held.release(pduObjs);