Skip to content

Commit d7c67a6

Browse files
committed
last fix
1 parent fcb203f commit d7c67a6

2 files changed

Lines changed: 28 additions & 29 deletions

File tree

src/nodes/NodeConnection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class NodeConnection<T extends GRPCClient> {
168168
public async destroy() {
169169
this.logger.info(`Destroying ${this.constructor.name}`);
170170
if (
171+
this.client != null &&
171172
this.client[asyncInit.status] !== 'destroying' &&
172173
!this.client[asyncInit.destroyed]
173174
) {

tests/nodes/NodeConnectionManager.termination.test.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path';
77
import os from 'os';
88
import { DB } from '@matrixai/db';
99
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
10-
import { _destroyed } from '@matrixai/async-init/dist/utils';
10+
import { destroyed } from '@matrixai/async-init/';
1111
import { IdInternal } from '@matrixai/id';
1212
import PolykeyAgent from '@/PolykeyAgent';
1313
import KeyManager from '@/keys/KeyManager';
@@ -402,7 +402,7 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
402402
);
403403
expect(connAndLock?.lock.isLocked()).toBe(false);
404404
if (firstConnection != null) {
405-
expect(firstConnection[_destroyed]).toBe(true);
405+
expect(firstConnection[destroyed]).toBe(true);
406406
}
407407
} finally {
408408
await nodeConnectionManager?.stop();
@@ -452,11 +452,11 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
452452
agentNodeId,
453453
async (connection) => {
454454
const client = connection.getClient();
455-
expect(connection[_destroyed]).toBe(false);
456-
expect(client[_destroyed]).toBe(false);
455+
expect(connection[destroyed]).toBe(false);
456+
expect(client[destroyed]).toBe(false);
457457
await polykeyAgent?.stop();
458-
expect(client[_destroyed]).toBe(true);
459-
expect(connection[_destroyed]).toBe(true);
458+
expect(client[destroyed]).toBe(true);
459+
expect(connection[destroyed]).toBe(true);
460460
// Breaking call
461461
const attemptP = client.echo(new utilsPB.EchoMessage());
462462
await expect(attemptP).rejects.toThrow();
@@ -473,7 +473,7 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
473473
);
474474
expect(connAndLock?.lock.isLocked()).toBe(false);
475475
if (firstConnection != null) {
476-
expect(firstConnection[_destroyed]).toBe(true);
476+
expect(firstConnection[destroyed]).toBe(true);
477477
}
478478
} finally {
479479
await nodeConnectionManager?.stop();
@@ -547,7 +547,7 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
547547
);
548548
expect(connAndLock?.lock.isLocked()).toBe(false);
549549
if (firstConnection != null) {
550-
expect(firstConnection[_destroyed]).toBe(true);
550+
expect(firstConnection[destroyed]).toBe(true);
551551
}
552552
} finally {
553553
await nodeConnectionManager?.stop();
@@ -621,7 +621,7 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
621621
);
622622
expect(connAndLock?.lock.isLocked()).toBe(false);
623623
if (firstConnection != null) {
624-
expect(firstConnection[_destroyed]).toBe(true);
624+
expect(firstConnection[destroyed]).toBe(true);
625625
}
626626
} finally {
627627
await nodeConnectionManager?.stop();
@@ -670,19 +670,18 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
670670
// Resolves if the shutdownCallback was called
671671
await nodeConnectionManager.withConnF(agentNodeId, async (connection) => {
672672
const client = connection.getClient();
673-
expect(connection[_destroyed]).toBe(false);
674-
expect(client[_destroyed]).toBe(false);
673+
expect(connection[destroyed]).toBe(false);
674+
expect(client[destroyed]).toBe(false);
675675

676676
// We want to watch for the killSelf event by hijacking the NodeConnectionmanagerInterface
677677
const oldKillSelf =
678-
// @ts-ignore: kidnap the interface
679-
connection.nodeConnectionManagerInterface.destroyCallback;
680-
// @ts-ignore: update the interface;
681-
connection.nodeConnectionManagerInterface.destroyCallback =
682-
async () => {
683-
await oldKillSelf();
684-
killSelfP.resolveP(null);
685-
};
678+
// @ts-ignore: kidnap the callback
679+
connection.destroyCallback;
680+
// @ts-ignore: update the callback;
681+
connection.destroyCallback = async () => {
682+
await oldKillSelf();
683+
killSelfP.resolveP(null);
684+
};
686685
await connection.destroy();
687686
});
688687

@@ -696,7 +695,7 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
696695
);
697696
expect(connAndLock?.lock.isLocked()).toBe(false);
698697
if (firstConnection != null) {
699-
expect(firstConnection[_destroyed]).toBe(true);
698+
expect(firstConnection[destroyed]).toBe(true);
700699
}
701700
} finally {
702701
await nodeConnectionManager?.stop();
@@ -743,16 +742,15 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
743742

744743
// We want to watch for the killSelf event by hijacking the NodeConnectionmanagerInterface
745744
const oldKillSelf =
746-
// @ts-ignore: kidnap the interface
747-
firstConnection?.nodeConnectionManagerInterface.destroyCallback;
745+
// @ts-ignore: kidnap the callback
746+
firstConnection?.destroyCallback;
748747
const killSelfP = promise<null>();
749748
if (firstConnection != null) {
750-
// @ts-ignore: update the interface;
751-
firstConnection.nodeConnectionManagerInterface.destroyCallback =
752-
async () => {
753-
if (oldKillSelf != null) await oldKillSelf();
754-
killSelfP.resolveP(null);
755-
};
749+
// @ts-ignore: update the callback;
750+
firstConnection.destroyCallback = async () => {
751+
if (oldKillSelf != null) await oldKillSelf();
752+
killSelfP.resolveP(null);
753+
};
756754
}
757755
await firstConnection?.destroy();
758756
// Wait for `killSelf` to resolve
@@ -765,7 +763,7 @@ describe(`${NodeConnectionManager.name} termination test`, () => {
765763
);
766764
expect(connAndLock?.lock.isLocked()).toBe(false);
767765
if (firstConnection != null) {
768-
expect(firstConnection[_destroyed]).toBe(true);
766+
expect(firstConnection[destroyed]).toBe(true);
769767
}
770768
} finally {
771769
await nodeConnectionManager?.stop();

0 commit comments

Comments
 (0)