From 9c471e694913771a06e05088041a9893dda3aed7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 4 Sep 2023 07:19:19 -0400 Subject: [PATCH] fix: fix outdated reads. port of s5 08c4bda5c1109673fba907ba119c9855fc3fcf68 0d2bf39845b37dd0b2ebe06be34c5d51e7060280 --- src/service/registry.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/service/registry.ts b/src/service/registry.ts index 53b4041..832a1f9 100644 --- a/src/service/registry.ts +++ b/src/service/registry.ts @@ -26,6 +26,7 @@ export class RegistryService { private node: S5Node; private logger: Logger; private streams: Map = new Map(); + private subs: Map = new Map(); constructor(node: S5Node) { this.node = node; @@ -125,7 +126,8 @@ export class RegistryService { async get(pk: Uint8Array): Promise { const key = new Multihash(pk); - if (this.streams.has(key.toString())) { + const keyString = key.toString(); + if (this.subs.has(keyString)) { this.logger.verbose(`[registry] get (subbed) ${key}`); let res = await this.getFromDB(pk); if (res !== null) { @@ -136,7 +138,10 @@ export class RegistryService { return this.getFromDB(pk); } else { this.sendRegistryRequest(pk); - this.streams.set(key.toString(), new EventEmitter()); + this.subs.set(keyString, key); + if (!this.streams.has(keyString)) { + this.streams.set(keyString, new EventEmitter()); + } let res = await this.getFromDB(pk); if (res === null) { this.logger.verbose(`[registry] get (clean) ${key}`);