From 22ed5ebe593b010f56c70a3dae03c9a53d6eefe9 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 26 Feb 2026 16:58:33 +0000 Subject: [PATCH] fix(typedsocket): reject pending requests on disconnect to avoid hanging promises --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/typedsocket.classes.typedsocket.ts | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index a436783..ab632d6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-02-26 - 4.1.1 - fix(typedsocket) +reject pending requests on disconnect to avoid hanging promises + +- Rejects all pending requests with Error('TypedSocket disconnected') when connection is lost +- Clears pendingRequests map to prevent memory leaks +- Preserves existing auto-reconnect scheduling behavior + ## 2025-12-04 - 4.1.0 - feat(typedsocket) Add SmartServe integration, tagging and improved client reconnect/backoff; update deps and tests diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 88e507b..f083eea 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@api.global/typedsocket', - version: '4.1.0', + version: '4.1.1', description: 'A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.' } diff --git a/ts/typedsocket.classes.typedsocket.ts b/ts/typedsocket.classes.typedsocket.ts index 9312214..11ca995 100644 --- a/ts/typedsocket.classes.typedsocket.ts +++ b/ts/typedsocket.classes.typedsocket.ts @@ -325,6 +325,12 @@ export class TypedSocket { this.updateStatus('disconnected'); + // Reject all pending requests — the connection is gone and they'll never receive a response + for (const [id, pending] of this.pendingRequests) { + pending.reject(new Error('TypedSocket disconnected')); + } + this.pendingRequests.clear(); + if (this.clientOptions?.autoReconnect && this.retryCount < this.clientOptions.maxRetries) { this.scheduleReconnect(); }