fix(device-edge): bound stalled Core channel connects
This commit is contained in:
@@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import { randomUUID, X509Certificate } from "node:crypto";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { connect as connectHttp2 } from "node:http2";
|
||||
import { createServer as createTcpServer } from "node:net";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { after, before, test } from "node:test";
|
||||
@@ -94,6 +95,34 @@ test("keeps the channel alive and reconnects without losing idempotency", async
|
||||
}
|
||||
});
|
||||
|
||||
test("bounds a stalled TCP/TLS handshake and reconnects", async () => {
|
||||
const sockets = new Set();
|
||||
const server = createTcpServer((socket) => {
|
||||
sockets.add(socket);
|
||||
socket.once("close", () => sockets.delete(socket));
|
||||
});
|
||||
await new Promise((resolve, reject) => {
|
||||
server.once("error", reject);
|
||||
server.listen(0, "127.0.0.1", resolve);
|
||||
});
|
||||
const core = createCoreClient({
|
||||
address: server.address(),
|
||||
connectTimeoutMs: 30,
|
||||
reconnectMinimumMs: 20,
|
||||
reconnectMaximumMs: 20,
|
||||
});
|
||||
try {
|
||||
await core.start();
|
||||
await waitFor(() => core.status().connectionAttempts >= 2, 1_000);
|
||||
assert.match(core.status().lastErrorCode, /connect_timeout/);
|
||||
assert.ok(core.status().reconnects >= 1);
|
||||
} finally {
|
||||
await core.stop();
|
||||
for (const socket of sockets) socket.destroy();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
});
|
||||
|
||||
test("rotates the Edge certificate through staged overlap and rejects retired identity", async () => {
|
||||
const edge = createEdgeServer();
|
||||
const address = await edge.start();
|
||||
@@ -430,6 +459,7 @@ function createCoreClient(options) {
|
||||
deadPeerMs: options.deadPeerMs ?? 150,
|
||||
reconnectMinimumMs: options.reconnectMinimumMs ?? 20,
|
||||
reconnectMaximumMs: options.reconnectMaximumMs ?? 80,
|
||||
connectTimeoutMs: options.connectTimeoutMs,
|
||||
random: () => 0,
|
||||
observeDiscovery: options.observeDiscovery ?? (async () => ({
|
||||
schemaVersion: "nodedc.device.discovery-view.v1",
|
||||
|
||||
Reference in New Issue
Block a user