From 16654cbba337e7d9a52e768a2685008aef84bf72 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Fri, 5 Jul 2024 23:25:42 +0200 Subject: [PATCH 1/2] fix memory leak in ts client. Old Promises including their return values were not garbage collected, because they were not removed from the `_requests` Map. fixes #60 --- CHANGELOG.md | 4 ++++ typescript/client.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dbcf53..84a31ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## Unreleased + +- ts client: fix memory leak + ## 0.5.3 - 2023-12-02 - Update axum diff --git a/typescript/client.ts b/typescript/client.ts index 7d8a383..2f3a114 100644 --- a/typescript/client.ts +++ b/typescript/client.ts @@ -40,6 +40,7 @@ export abstract class BaseTransport if (!handler) return; // TODO: Handle error. if (response.error) handler.reject(response.error); else handler.resolve(response.result); + this._requests.delete(response.id) } notification(method: string, params?: Params): void { From 931d8a25a8a0668bd9890352ae12e5f7634d63cb Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Sat, 6 Jul 2024 00:26:52 +0200 Subject: [PATCH 2/2] move delete function up --- typescript/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/client.ts b/typescript/client.ts index 2f3a114..67f6fb9 100644 --- a/typescript/client.ts +++ b/typescript/client.ts @@ -38,9 +38,9 @@ export abstract class BaseTransport if (!response.id) return; // TODO: Handle error. const handler = this._requests.get(response.id); if (!handler) return; // TODO: Handle error. + this._requests.delete(response.id) if (response.error) handler.reject(response.error); else handler.resolve(response.result); - this._requests.delete(response.id) } notification(method: string, params?: Params): void {