Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing intermittent failures due to js-quic stream errors #725

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@matrixai/id": "^3.3.6",
"@matrixai/logger": "^3.1.2",
"@matrixai/mdns": "^1.2.6",
"@matrixai/quic": "^1.2.6",
"@matrixai/quic": "^1.2.7",
"@matrixai/resources": "^1.1.5",
"@matrixai/rpc": "^0.5.1",
"@matrixai/timer": "^1.1.3",
Expand Down
35 changes: 29 additions & 6 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
utils as quicUtils,
} from '@matrixai/quic';
import { withF } from '@matrixai/resources';
import { middleware as rpcMiddleware, RPCServer } from '@matrixai/rpc';
import {
errors as rpcErrors,
middleware as rpcMiddleware,
RPCServer,
} from '@matrixai/rpc';
import Logger from '@matrixai/logger';
import { Timer } from '@matrixai/timer';
import { IdInternal } from '@matrixai/id';
Expand Down Expand Up @@ -850,14 +854,23 @@ class NodeConnectionManager {
this.keyRing.keyPair,
data,
);
const addressMessage =
await client.methods.nodesConnectionSignalInitial(
const addressMessage = await client.methods
.nodesConnectionSignalInitial(
{
targetNodeIdEncoded: nodesUtils.encodeNodeId(nodeIdTarget),
signature: signature.toString('base64url'),
},
ctx,
);
)
.catch((e) => {
if (e instanceof rpcErrors.ErrorRPCHandlerFailed) {
throw new nodesErrors.ErrorNodeConnectionManagerSignalFailed(
'Failed initial signal step triggering `nodesConnectionSignalInitial`',
{ cause: e },
);
}
throw e;
});
return {
host: addressMessage.host as Host,
port: addressMessage.port as Port,
Expand Down Expand Up @@ -940,7 +953,7 @@ class NodeConnectionManager {
/**
* Gets the existing active connection for the target node
*/
public getConnection(nodeId): ConnectionAndTimer | undefined {
public getConnection(nodeId: NodeId): ConnectionAndTimer | undefined {
const nodeIdString = nodeId.toString() as NodeIdString;
const connectionsEntry = this.connections.get(nodeIdString);
if (connectionsEntry == null) return;
Expand Down Expand Up @@ -1292,7 +1305,17 @@ class NodeConnectionManager {
.then(
() => {},
(e) => {
if (!nodesUtils.isConnectionError(e)) throw e;
// If it's a connection error or missing handler then it's a signalling failure
if (
nodesUtils.isConnectionError(e) ||
e instanceof rpcErrors.ErrorRPCHandlerFailed
) {
new nodesErrors.ErrorNodeConnectionManagerSignalFailed(
'Failed final signal step triggering `nodesConnectionSignalFinal`',
{ cause: e },
);
}
throw e;
},
)
.finally(() => {
Expand Down
8 changes: 8 additions & 0 deletions src/nodes/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ class ErrorNodeConnectionManagerRequestRateExceeded<
exitCode = sysexits.TEMPFAIL;
}

class ErrorNodeConnectionManagerSignalFailed<
T,
> extends ErrorNodeConnectionManager<T> {
static description = 'Failed to signal hole punching';
exitCode = sysexits.TEMPFAIL;
}

class ErrorNodePingFailed<T> extends ErrorNodes<T> {
static description =
'Failed to ping the node when attempting to authenticate';
Expand Down Expand Up @@ -240,6 +247,7 @@ export {
ErrorNodeConnectionManagerMultiConnectionFailed,
ErrorNodeConnectionManagerConnectionNotFound,
ErrorNodeConnectionManagerRequestRateExceeded,
ErrorNodeConnectionManagerSignalFailed,
ErrorNodePingFailed,
ErrorNodePermissionDenied,
ErrorNodeLookupNotFound,
Expand Down
11 changes: 6 additions & 5 deletions src/vaults/VaultInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ class VaultInternal {
vaultNameOrId: vaultNameOrId_,
action: vaultAction,
});

const result = vaultsGitInfoGetStream.meta?.result;
if (result == null || !utils.isObject(result)) {
utils.never('`result` must be a defined object');
Expand All @@ -832,6 +833,11 @@ class VaultInternal {
const vaultName = result.vaultName;
const remoteVaultId = ids.parseVaultId(result.vaultIdEncoded);

const vaultsGitPackGetStream = await client.methods.vaultsGitPackGet({
nameOrId: result.vaultIdEncoded as string,
vaultAction,
});

return [
async function ({
url,
Expand All @@ -855,14 +861,9 @@ class VaultInternal {
statusMessage: 'OK',
};
} else if (method === 'POST') {
const vaultsGitPackGetStream = await client.methods.vaultsGitPackGet({
nameOrId: result.vaultIdEncoded as string,
vaultAction,
});
const writer = vaultsGitPackGetStream.writable.getWriter();
await writer.write(body[0]);
await writer.close();

return {
url: url,
method: method,
Expand Down
1 change: 0 additions & 1 deletion tests/vaults/VaultManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ describe('VaultManager', () => {
vaultsErrors.ErrorVaultsPermissionDenied,
);
});
// FIXME: Test has been disabled due to non-deterministic failures in CI/CD
test(
'can pull a cloned vault',
async () => {
Expand Down