From fdb6064721a406266f74cb9349d9163cd488e6ea Mon Sep 17 00:00:00 2001 From: gfrancz <52467377+gfrancz@users.noreply.github.com> Date: Mon, 27 Jan 2025 21:46:34 -0500 Subject: [PATCH 1/2] fix: xds-client LrsCallState statsTimer memory leak --- packages/grpc-js-xds/src/xds-client.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/grpc-js-xds/src/xds-client.ts b/packages/grpc-js-xds/src/xds-client.ts index 1ebeccc38..168fc5ec5 100644 --- a/packages/grpc-js-xds/src/xds-client.ts +++ b/packages/grpc-js-xds/src/xds-client.ts @@ -688,6 +688,13 @@ class LrsCallState { this.sendStats(); } + destroy() { + if (this.statsTimer) { + this.statsTimer = clearInterval(this.statsTimer); + } + return null; + } + private handleStreamStatus(status: StatusObject) { this.client.trace( 'LRS stream ended. code=' + status.code + ' details= ' + status.details @@ -938,7 +945,7 @@ class XdsSingleServerClient { } handleLrsStreamEnd() { - this.lrsCallState = null; + this.lrsCallState = this.lrsCallState ? this.lrsCallState.destroy() : null; /* The backoff timer would start the stream when it finishes. If it is not * running, restart the stream immediately. */ if (!this.lrsBackoff.isRunning()) { From 6dc3abe798994bcde5b7a0d316cf3937bc23a586 Mon Sep 17 00:00:00 2001 From: gfrancz <52467377+gfrancz@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:55:16 -0500 Subject: [PATCH 2/2] Fix type issue by setting the attribute separately Co-authored-by: ws-gregm <55088361+ws-gregm@users.noreply.github.com> --- packages/grpc-js-xds/src/xds-client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/grpc-js-xds/src/xds-client.ts b/packages/grpc-js-xds/src/xds-client.ts index 168fc5ec5..785c11943 100644 --- a/packages/grpc-js-xds/src/xds-client.ts +++ b/packages/grpc-js-xds/src/xds-client.ts @@ -690,7 +690,8 @@ class LrsCallState { destroy() { if (this.statsTimer) { - this.statsTimer = clearInterval(this.statsTimer); + clearInterval(this.statsTimer); + this.statsTimer = null; } return null; }