From 01663bb7b4c665132e973ddc6d16e2cd95c18efe Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Wed, 30 Oct 2024 21:01:27 +0000 Subject: [PATCH 1/2] fix: memory leak in `DataStore` We have a set of promises waiting to be indexed, and we never removed these promises from the set. This fixes that memory leak. --- src/datastore/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/datastore/index.js b/src/datastore/index.js index 6a29e78a..bf3d8be3 100644 --- a/src/datastore/index.js +++ b/src/datastore/index.js @@ -111,6 +111,7 @@ export class DataStore extends TypedEmitter { const pending = this.#pendingIndex.get(versionId) if (!pending) continue pending.resolve() + this.#pendingIndex.delete(versionId) } for (const schemaName of this.schemas) { // Unsupported initially From af184f27f8eb186f0053b1ca6d6cbe593cd9c0fa Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Wed, 30 Oct 2024 23:09:32 +0000 Subject: [PATCH 2/2] Move deletion --- src/datastore/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datastore/index.js b/src/datastore/index.js index bf3d8be3..19b9ddd8 100644 --- a/src/datastore/index.js +++ b/src/datastore/index.js @@ -111,7 +111,6 @@ export class DataStore extends TypedEmitter { const pending = this.#pendingIndex.get(versionId) if (!pending) continue pending.resolve() - this.#pendingIndex.delete(versionId) } for (const schemaName of this.schemas) { // Unsupported initially @@ -166,6 +165,7 @@ export class DataStore extends TypedEmitter { const deferred = pDefer() this.#pendingIndex.set(versionId, deferred) await deferred.promise + this.#pendingIndex.delete(versionId) return /** @type {Extract} */ ( decode(block, { coreDiscoveryKey, index })