From f8b556f536a026edd4a29e364a5dcc38b1319bcc Mon Sep 17 00:00:00 2001 From: James Ebert Date: Tue, 8 Feb 2022 10:41:44 -0700 Subject: [PATCH] chore: update recursive backoff & trust ping record updates Signed-off-by: James Ebert --- .../src/modules/connections/services/ConnectionService.ts | 5 ++++- packages/core/src/modules/routing/RecipientModule.ts | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/src/modules/connections/services/ConnectionService.ts b/packages/core/src/modules/connections/services/ConnectionService.ts index f4d95201e3..bc3cef2c26 100644 --- a/packages/core/src/modules/connections/services/ConnectionService.ts +++ b/packages/core/src/modules/connections/services/ConnectionService.ts @@ -391,7 +391,10 @@ export class ConnectionService { // - maybe this shouldn't be in the connection service? const trustPing = new TrustPingMessage(config) - await this.updateState(connectionRecord, ConnectionState.Complete) + // Only update connection record and emit an event if the state is not already 'Complete' + if (connectionRecord.state !== ConnectionState.Complete) { + await this.updateState(connectionRecord, ConnectionState.Complete) + } return { connectionRecord: connectionRecord, diff --git a/packages/core/src/modules/routing/RecipientModule.ts b/packages/core/src/modules/routing/RecipientModule.ts index badc0ed44c..827d511ca2 100644 --- a/packages/core/src/modules/routing/RecipientModule.ts +++ b/packages/core/src/modules/routing/RecipientModule.ts @@ -5,8 +5,8 @@ import type { ConnectionRecord } from '../connections' import type { MediationStateChangedEvent } from './RoutingEvents' import type { MediationRecord } from './index' -import { firstValueFrom, interval, ReplaySubject } from 'rxjs' -import { filter, first, takeUntil, throttleTime, timeout, delay, tap } from 'rxjs/operators' +import { firstValueFrom, interval, ReplaySubject, timer } from 'rxjs' +import { filter, first, takeUntil, throttleTime, timeout, tap, delayWhen } from 'rxjs/operators' import { Lifecycle, scoped } from 'tsyringe' import { AgentConfig } from '../../agent/AgentConfig' @@ -140,7 +140,7 @@ export class RecipientModule { // Increase the interval (recursive back-off) tap(() => (interval *= 2)), // Wait for interval time before reconnecting - delay(interval) + delayWhen(() => timer(interval)) ) .subscribe(async () => { this.logger.warn(