From 16e9897eb4169f2c50959dbfa83a47344f9ea92a Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 16 May 2024 14:41:29 -0700 Subject: [PATCH 01/12] fix: type error --- packages/utils/src/abstract-session.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index 3a1c468dd..a8fcd048c 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -81,7 +81,7 @@ export abstract class AbstractSession({ + const queue = new Queue({ concurrency: this.maxProviders }) queue.addEventListener('error', () => {}) From 51ea671dfd112effb324f134b247ba536561181e Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 16 May 2024 15:01:09 -0700 Subject: [PATCH 02/12] test: add a test that shows infinite loop error --- packages/utils/test/abstract-session.spec.ts | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/utils/test/abstract-session.spec.ts b/packages/utils/test/abstract-session.spec.ts index 43228ff21..af5678565 100644 --- a/packages/utils/test/abstract-session.spec.ts +++ b/packages/utils/test/abstract-session.spec.ts @@ -233,4 +233,35 @@ describe('abstract-session', () => { })).to.eventually.be.rejected() .with.property('code', 'ABORT_ERR') }) + + it('should not make multiple requests to the only found provider', async () => { + const session = new Session() + + const cid = CID.parse('bafybeifaymukvfkyw6xgh4th7tsctiifr4ea2btoznf46y6b2fnvikdczi') + + const providers: SessionPeer[] = [ + { + id: await createEd25519PeerId() + } + ] + + // const deferredFindProviders = pDefer() + session.findNewProviders.callsFake(async function * () { + yield providers[0] + }) + + session.queryProvider.callsFake(async () => { + // always fails + throw new Error('Urk!') + }) + + await expect(session.retrieve(cid, { signal: AbortSignal.timeout(2000) })).to.eventually.be.rejected() + + expect(session.findNewProviders.callCount).to.equal(1) + + expect(session.providers).to.have.lengthOf(0) + + // await expect(session.retrieve(cid)).to.eventually.deep.equal(block) + expect(session.providers.includes(providers[0])).to.be.false() + }) }) From a4e0f1b627999ff6308ea4937a772aa360b4e8c9 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 16 May 2024 16:08:41 -0700 Subject: [PATCH 03/12] fix: no infinite searching when never finding new providers --- packages/utils/src/abstract-session.ts | 18 +++++++++++-- packages/utils/test/abstract-session.spec.ts | 27 +++++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index a8fcd048c..36a215caf 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -33,6 +33,13 @@ export abstract class AbstractSession = {}): Promise { @@ -95,8 +103,9 @@ export abstract class AbstractSession { - if (foundBlock || options.signal?.aborted === true) { - // we either found the block or the user gave up + if (foundBlock || options.signal?.aborted === true || this.noNewProviders) { + // we either found the block, the user gave up, or cannot find any more providers + this.log('session aborted') return } @@ -246,6 +255,11 @@ export abstract class AbstractSession { .with.property('code', 'ABORT_ERR') }) - it('should not make multiple requests to the only found provider', async () => { - const session = new Session() + it('should not make multiple requests to the only found provider', async function () { + this.timeout(1000) + const session: Session | null = new Session() const cid = CID.parse('bafybeifaymukvfkyw6xgh4th7tsctiifr4ea2btoznf46y6b2fnvikdczi') - + const id = await createEd25519PeerId() // same provider const providers: SessionPeer[] = [ { - id: await createEd25519PeerId() + id + }, + { + id } ] - // const deferredFindProviders = pDefer() - session.findNewProviders.callsFake(async function * () { + session.findNewProviders.onFirstCall().callsFake(async function * () { yield providers[0] }) + session.findNewProviders.onSecondCall().callsFake(async function * () { + yield providers[1] + }) + // eslint-disable-next-line require-yield + session.findNewProviders.callsFake(async function * () { + yield providers[1] + }) session.queryProvider.callsFake(async () => { // always fails throw new Error('Urk!') }) - await expect(session.retrieve(cid, { signal: AbortSignal.timeout(2000) })).to.eventually.be.rejected() + await expect(session.retrieve(cid)).to.eventually.be.rejected() - expect(session.findNewProviders.callCount).to.equal(1) + expect(session.findNewProviders.callCount).to.equal(4) expect(session.providers).to.have.lengthOf(0) - // await expect(session.retrieve(cid)).to.eventually.deep.equal(block) expect(session.providers.includes(providers[0])).to.be.false() }) }) From 1461d8b3f24a6e504d06f5501620ed876a596f31 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 16 May 2024 16:11:57 -0700 Subject: [PATCH 04/12] chore: simplify infinite loop test --- packages/utils/test/abstract-session.spec.ts | 22 ++------------------ 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/utils/test/abstract-session.spec.ts b/packages/utils/test/abstract-session.spec.ts index 9272c3d08..e4b633954 100644 --- a/packages/utils/test/abstract-session.spec.ts +++ b/packages/utils/test/abstract-session.spec.ts @@ -240,24 +240,10 @@ describe('abstract-session', () => { const cid = CID.parse('bafybeifaymukvfkyw6xgh4th7tsctiifr4ea2btoznf46y6b2fnvikdczi') const id = await createEd25519PeerId() // same provider - const providers: SessionPeer[] = [ - { - id - }, - { + session.findNewProviders.callsFake(async function * () { + yield { id } - ] - - session.findNewProviders.onFirstCall().callsFake(async function * () { - yield providers[0] - }) - session.findNewProviders.onSecondCall().callsFake(async function * () { - yield providers[1] - }) - // eslint-disable-next-line require-yield - session.findNewProviders.callsFake(async function * () { - yield providers[1] }) session.queryProvider.callsFake(async () => { @@ -268,9 +254,5 @@ describe('abstract-session', () => { await expect(session.retrieve(cid)).to.eventually.be.rejected() expect(session.findNewProviders.callCount).to.equal(4) - - expect(session.providers).to.have.lengthOf(0) - - expect(session.providers.includes(providers[0])).to.be.false() }) }) From 97d21cd40ec4690902eb980f03746c82db3a12a2 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 16 May 2024 16:31:48 -0700 Subject: [PATCH 05/12] test: update expected error in bitswap session test --- packages/bitswap/test/session.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bitswap/test/session.spec.ts b/packages/bitswap/test/session.spec.ts index ad8fc1329..ea85c7baa 100644 --- a/packages/bitswap/test/session.spec.ts +++ b/packages/bitswap/test/session.spec.ts @@ -112,7 +112,7 @@ describe('session', () => { })()) await expect(session.retrieve(cid)).to.eventually.be.rejected - .with.property('code', 'ERR_INSUFFICIENT_PROVIDERS_FOUND') + .with.property('code', 'ERR_NO_NEW_PROVIDERS_FOUND') }) it('should error when creating a session when no providers have the block', async () => { @@ -137,7 +137,7 @@ describe('session', () => { const session = createBitswapSession(components, {}) await expect(session.retrieve(cid)).to.eventually.be.rejected - .with.property('code', 'ERR_INSUFFICIENT_PROVIDERS_FOUND') + .with.property('code', 'ERR_NO_NEW_PROVIDERS_FOUND') }) it('should exclude non-bitswap providers from the session', async () => { From 46e5e3c594405778c0bca29a37b2f0d9002cb119 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 17 May 2024 14:08:25 -0700 Subject: [PATCH 06/12] fix: abstract-session cleanup and duplicate provider handling --- .../src/trustless-gateway/session.ts | 1 + .../test/trustless-gateway-sessions.spec.ts | 38 ++- packages/utils/src/abstract-session.ts | 250 +++++++++++------- packages/utils/test/abstract-session.spec.ts | 4 +- 4 files changed, 187 insertions(+), 106 deletions(-) diff --git a/packages/block-brokers/src/trustless-gateway/session.ts b/packages/block-brokers/src/trustless-gateway/session.ts index 9d26d7435..933578acf 100644 --- a/packages/block-brokers/src/trustless-gateway/session.ts +++ b/packages/block-brokers/src/trustless-gateway/session.ts @@ -42,6 +42,7 @@ class TrustlessGatewaySession extends AbstractSession { + this.log('findNewProviders called') yield * findHttpGatewayProviders(cid, this.routing, this.logger, this.allowInsecure, this.allowLocal, options) } diff --git a/packages/block-brokers/test/trustless-gateway-sessions.spec.ts b/packages/block-brokers/test/trustless-gateway-sessions.spec.ts index f2216ceb0..b0220368d 100644 --- a/packages/block-brokers/test/trustless-gateway-sessions.spec.ts +++ b/packages/block-brokers/test/trustless-gateway-sessions.spec.ts @@ -99,13 +99,43 @@ describe('trustless-gateway sessions', () => { ] } - components.routing.findProviders.returns(async function * () { - yield prov + components.routing.findProviders.callsFake(async function * () { yield prov - yield prov - }()) + }) await expect(session.retrieve(cid)).to.eventually.deep.equal(block) expect(queryProviderSpy.callCount).to.equal(1) }) + + it('should ignore duplicate providers when unable to retrieve a block', async () => { + const session = createTrustlessGatewaySession(components, { + allowInsecure: true, + allowLocal: true + }) + + // changed the CID to end in `aa` instead of `aq` + const cid = CID.parse('bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aa') + + const queryProviderSpy = Sinon.spy(session, 'queryProvider') + const findNewProvidersSpy = Sinon.spy(session, 'findNewProviders') + const hasProviderSpy = Sinon.spy(session, 'hasProvider') + + const prov = { + id: await createEd25519PeerId(), + multiaddrs: [ + uriToMultiaddr(process.env.TRUSTLESS_GATEWAY ?? '') + ] + } + + components.routing.findProviders.callsFake(async function * () { + yield prov + }) + + await expect(session.retrieve(cid)).to.eventually.be.rejected() + expect(hasProviderSpy.callCount).to.be.greaterThanOrEqual(2) + expect(hasProviderSpy.getCall(0).returnValue).to.be.false() + expect(hasProviderSpy.getCall(1).returnValue).to.be.true() + expect(findNewProvidersSpy.callCount).to.be.greaterThanOrEqual(2) + expect(queryProviderSpy.callCount).to.equal(1) + }) }) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index 36a215caf..f8c6e961a 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -32,13 +32,9 @@ export abstract class AbstractSession + findProviderQueue: Queue + queryProviderQueue: Queue constructor (components: AbstractSessionComponents, init: AbstractCreateSessionOptions) { super() @@ -52,7 +48,13 @@ export abstract class AbstractSession = {}): Promise { @@ -64,10 +66,18 @@ export abstract class AbstractSession = pDefer() this.requests.set(cidStr, deferred.promise) + const peerAddedToSessionListener = (event: CustomEvent): void => { + this.log('peer added to session...') + this.addQueryProviderJob(cid, event.detail, options) + } + + // add new session peers to query as they are discovered + this.addEventListener('provider', peerAddedToSessionListener) + if (this.providers.length === 0) { let first = false @@ -82,114 +92,133 @@ export abstract class AbstractSession { + this.log('querying existing provider %o', this.toEvictionKey(provider)) + return this.addQueryProviderJob(cid, provider, options) + })) } - let foundBlock = false + let findProvidersErrored = false + this.findProviderQueue.addEventListener('failure', (evt) => { + this.log.error('error finding new providers for %c', cid, evt.detail.error) - // this queue manages outgoing requests - as new peers are added to the - // session they will be added to the queue so we can request the current - // block from multiple peers as they are discovered - const queue = new Queue({ - concurrency: this.maxProviders - }) - queue.addEventListener('error', () => {}) - queue.addEventListener('failure', (evt) => { - this.log.error('error querying provider %o, evicting from session', evt.detail.job.options.provider, evt.detail.error) - this.evict(evt.detail.job.options.provider) - }) - queue.addEventListener('success', (evt) => { - // peer has sent block, return it to the caller - foundBlock = true - deferred.resolve(evt.detail.result) - }) - queue.addEventListener('idle', () => { - if (foundBlock || options.signal?.aborted === true || this.noNewProviders) { - // we either found the block, the user gave up, or cannot find any more providers - this.log('session aborted') + findProvidersErrored = true + if (['ERR_INSUFFICIENT_PROVIDERS_FOUND'].includes((evt.detail.error as CodeError).code)) { + deferred.reject(evt.detail.error) return } + }) - // find more session peers and retry - Promise.resolve() - .then(async () => { - this.log('no session peers had block for for %c, finding new providers', cid) - - // evict this.minProviders random providers to make room for more - for (let i = 0; i < this.minProviders; i++) { - if (this.providers.length === 0) { - break - } - - const provider = this.providers[Math.floor(Math.random() * this.providers.length)] - this.evict(provider) - } + this.findProviderQueue.addEventListener('idle', () => { + this.log.trace('findProviderQueue idle') + if (options.signal?.aborted === true && !foundBlock) { + deferred.reject(new CodeError(options.signal.reason, 'ABORT_ERR')) + return + } - // find new providers for the CID - await this.findProviders(cid, this.minProviders, options) - - // keep trying until the abort signal fires - this.log('found new providers re-retrieving %c', cid) - this.requests.delete(cidStr) - deferred.resolve(await this.retrieve(cid, options)) - }) - .catch(err => { - this.log.error('could not find new providers for %c', cid, err) - deferred.reject(err) - }) + if (foundBlock || findProvidersErrored || options.signal?.aborted === true) { + return + } + // continuously find new providers while we haven't found the block and signal is not aborted + this.addFindProviderJob(cid, options) }) - const peerAddedToSessionListener = (event: CustomEvent): void => { - queue.add(async () => { - return this.queryProvider(cid, event.detail, options) - }, { - provider: event.detail - }) - .catch(err => { - if (options.signal?.aborted === true) { - // skip logging error if signal was aborted because abort can happen - // on success (e.g. another session found the block) - return - } - - this.log.error('error retrieving session block for %c', cid, err) - }) - } - // add new session peers to query as they are discovered - this.addEventListener('provider', peerAddedToSessionListener) + this.queryProviderQueue.addEventListener('failure', (evt) => { + this.log.error('error querying provider %o, evicting from session', evt.detail.job.options.provider, evt.detail.error) + this.evict(evt.detail.job.options.provider) + }) - // query each session peer directly - Promise.all([...this.providers].map(async (provider) => { - return queue.add(async () => { - return this.queryProvider(cid, provider, options) - }, { - provider - }) - })) - .catch(err => { - if (options.signal?.aborted === true) { - // skip logging error if signal was aborted because abort can happen - // on success (e.g. another session found the block) - return - } + this.queryProviderQueue.addEventListener('success', (event) => { + this.log.trace('queryProviderQueue success') + foundBlock = true + // this.findProviderQueue.clear() + deferred.resolve(event.detail.result) + }) - this.log.error('error retrieving session block for %c', cid, err) - }) + this.queryProviderQueue.addEventListener('idle', () => { + this.log.trace('queryProviderQueue is idle') + if (foundBlock) { + return + } + if (options.signal?.aborted === true) { + // if the signal was aborted, we should reject the request + deferred.reject(options.signal.reason) + return + } + // we're done querying found providers.. if we can't find new providers, we should reject + if (findProvidersErrored) { + deferred.reject(new CodeError('Done querying all found providers and unable to retrieve the block', 'ERR_NO_PROVIDERS_HAD_BLOCK')) + return + } + // otherwise, we're still waiting for more providers to query + this.log('waiting for more providers to query') + // if this.findProviders is not running, start it + if (this.findProviderQueue.running === 0) { + this.addFindProviderJob(cid, options) + } + }) try { + // this.intialPeerSearchComplete = this.findProviders(cid, this.minProviders, options) return await deferred.promise } finally { + this.log('finally block, cleaning up session') this.removeEventListener('provider', peerAddedToSessionListener) - queue.clear() + this.findProviderQueue.clear() + this.queryProviderQueue.clear() this.requests.delete(cidStr) } } + addFindProviderJob(cid: CID, options: AbortOptions): any { + return this.findProviderQueue.add(async () => { + await this.findProviders(cid, this.minProviders, options) + }, { signal: options.signal }) + .catch(err => { + if (options.signal?.aborted === true) { + // skip logging error if signal was aborted because abort can happen + // on success (e.g. another session found the block) + return + } + }) + } + + addQueryProviderJob(cid: CID, provider: Provider, options: AbortOptions): any { + return this.queryProviderQueue.add(async () => { + return this.queryProvider(cid, provider, options) + }, { + provider, + signal: options.signal + }).catch(err => { + if (options.signal?.aborted === true) { + // skip logging error if signal was aborted because abort can happen + // on success (e.g. another session found the block) + return + } + }) + } + evict (provider: Provider): void { + this.log('evicting provider %o', provider) this.evictionFilter.add(this.toEvictionKey(provider)) + this.evictionFilter2.add(this.toEvictionKey(provider).toString()) + this.log('provider added to evictionFilter') const index = this.providers.findIndex(prov => this.equals(prov, provider)) + this.log('index of provider in this.providers: %d', index) if (index === -1) { + this.log('tried to evict provider, but it was not in this.providers') return } @@ -202,19 +231,36 @@ export abstract class AbstractSession this.equals(prov, provider)) != null) { + if (this.providers.some(prov => this.equals(prov, provider))) { + this.log('this.providers already has provider') return true + } else { + this.log('this.providers does not have provider') } // dedupe failed session peers if (this.isEvicted(provider)) { + this.log('provider was previously evicted') + return true + } else { + this.log('provider was not previously evicted') + } + if (this.evictionFilter2.has(this.toEvictionKey(provider).toString())) { + this.log('provider was *actually* previously evicted') return true } return false } + /** + * @param cid - The CID of the block to find providers for + * @param count - The number of providers to find + * @param options - AbortOptions + * @returns + */ private async findProviders (cid: CID, count: number, options: AbortOptions): Promise { + this.log('findProviders called') const deferred: DeferredPromise = pDefer() let found = 0 @@ -225,23 +271,32 @@ export abstract class AbstractSession { }) it('should not make multiple requests to the only found provider', async function () { - this.timeout(1000) const session: Session | null = new Session() const cid = CID.parse('bafybeifaymukvfkyw6xgh4th7tsctiifr4ea2btoznf46y6b2fnvikdczi') @@ -253,6 +252,7 @@ describe('abstract-session', () => { await expect(session.retrieve(cid)).to.eventually.be.rejected() - expect(session.findNewProviders.callCount).to.equal(4) + expect(session.findNewProviders.callCount).to.be.greaterThanOrEqual(2) + expect(session.queryProvider.callCount).to.equal(1) }) }) From 546faf4860ba10fccea3b415ec95d065ce28f676 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 20 May 2024 08:09:36 -0700 Subject: [PATCH 07/12] test: use original error code --- packages/bitswap/test/session.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bitswap/test/session.spec.ts b/packages/bitswap/test/session.spec.ts index ea85c7baa..ad8fc1329 100644 --- a/packages/bitswap/test/session.spec.ts +++ b/packages/bitswap/test/session.spec.ts @@ -112,7 +112,7 @@ describe('session', () => { })()) await expect(session.retrieve(cid)).to.eventually.be.rejected - .with.property('code', 'ERR_NO_NEW_PROVIDERS_FOUND') + .with.property('code', 'ERR_INSUFFICIENT_PROVIDERS_FOUND') }) it('should error when creating a session when no providers have the block', async () => { @@ -137,7 +137,7 @@ describe('session', () => { const session = createBitswapSession(components, {}) await expect(session.retrieve(cid)).to.eventually.be.rejected - .with.property('code', 'ERR_NO_NEW_PROVIDERS_FOUND') + .with.property('code', 'ERR_INSUFFICIENT_PROVIDERS_FOUND') }) it('should exclude non-bitswap providers from the session', async () => { From 0343733a1a4ab725834d712d568b8db4983e0e8e Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 20 May 2024 09:45:24 -0700 Subject: [PATCH 08/12] chore: revert unnecessary change --- packages/block-brokers/src/trustless-gateway/session.ts | 1 - .../block-brokers/test/trustless-gateway-sessions.spec.ts | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/block-brokers/src/trustless-gateway/session.ts b/packages/block-brokers/src/trustless-gateway/session.ts index 933578acf..9d26d7435 100644 --- a/packages/block-brokers/src/trustless-gateway/session.ts +++ b/packages/block-brokers/src/trustless-gateway/session.ts @@ -42,7 +42,6 @@ class TrustlessGatewaySession extends AbstractSession { - this.log('findNewProviders called') yield * findHttpGatewayProviders(cid, this.routing, this.logger, this.allowInsecure, this.allowLocal, options) } diff --git a/packages/block-brokers/test/trustless-gateway-sessions.spec.ts b/packages/block-brokers/test/trustless-gateway-sessions.spec.ts index b0220368d..93dfe9f04 100644 --- a/packages/block-brokers/test/trustless-gateway-sessions.spec.ts +++ b/packages/block-brokers/test/trustless-gateway-sessions.spec.ts @@ -99,9 +99,11 @@ describe('trustless-gateway sessions', () => { ] } - components.routing.findProviders.callsFake(async function * () { + components.routing.findProviders.returns(async function * () { yield prov - }) + yield prov + yield prov + }()) await expect(session.retrieve(cid)).to.eventually.deep.equal(block) expect(queryProviderSpy.callCount).to.equal(1) From 65200aa97363b592fe485aa2f60f4f03038a7683 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 20 May 2024 09:47:20 -0700 Subject: [PATCH 09/12] fix: improve failure state handling for sessions --- packages/utils/src/abstract-session.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index faa15f3aa..fe8902fba 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -111,8 +111,16 @@ export abstract class AbstractSession Date: Mon, 20 May 2024 09:54:16 -0700 Subject: [PATCH 10/12] chore: code cleanup --- packages/utils/src/abstract-session.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index fe8902fba..608107556 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -146,7 +146,6 @@ export abstract class AbstractSession { this.log.trace('queryProviderQueue success') foundBlock = true - // this.findProviderQueue.clear() deferred.resolve(event.detail.result) }) @@ -174,7 +173,6 @@ export abstract class AbstractSession { if (options.signal?.aborted === true) { - // skip logging error if signal was aborted because abort can happen - // on success (e.g. another session found the block) + // skip logging error if signal was aborted because abort can happen + // on success (e.g. another session found the block) return } this.log.error('could not find new providers for %c', cid, err) @@ -217,12 +215,10 @@ export abstract class AbstractSession this.equals(prov, provider)) - this.log('index of provider in this.providers: %d', index) if (index === -1) { - this.log('tried to evict provider, but it was not in this.providers') + this.log.trace('tried to evict provider, but it was not in this.providers') return } @@ -251,7 +247,6 @@ export abstract class AbstractSession { this.log('findProviders called') @@ -266,9 +261,7 @@ export abstract class AbstractSession Date: Mon, 20 May 2024 09:56:19 -0700 Subject: [PATCH 11/12] chore: remove more unnecessary changes --- packages/utils/src/abstract-session.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index 608107556..70309404a 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -143,10 +143,10 @@ export abstract class AbstractSession { + this.queryProviderQueue.addEventListener('success', (evt) => { this.log.trace('queryProviderQueue success') foundBlock = true - deferred.resolve(event.detail.result) + deferred.resolve(evt.detail.result) }) this.queryProviderQueue.addEventListener('idle', () => { From 86e6f115cf10ed2166e36bbf89b2120a509c4369 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 20 May 2024 09:59:36 -0700 Subject: [PATCH 12/12] chore: final code cleanup --- packages/utils/src/abstract-session.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index 70309404a..4cf9d809c 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -175,7 +175,7 @@ export abstract class AbstractSession { - this.log('findProviders called') const deferred: DeferredPromise = pDefer() let found = 0 @@ -266,10 +265,8 @@ export abstract class AbstractSession