fix(device-edge): bound stalled Core channel connects

This commit is contained in:
Codex
2026-08-12 09:26:40 +03:00
parent d8c0e9f3b1
commit 020d4dbad7
2 changed files with 49 additions and 0 deletions
@@ -19,6 +19,7 @@ import {
// Runtime-owned transport implementation; kept inside the deployable Core context.
const CHANNEL_TRACKER_SESSION_ID = "channel:control";
const CHANNEL_PROFILE_REF = "channel.control.v1";
const DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
export function createDeviceGatewayCoreChannelClient(options = {}) {
const config = normalizeConfig(options);
@@ -129,6 +130,7 @@ export function createDeviceGatewayCoreChannelClient(options = {}) {
edgeSequence: 0,
coreSequence: 0,
lastEdgeActivityAt: config.clock(),
connectTimer: null,
heartbeatTimer: null,
ready: false,
closed: false,
@@ -151,6 +153,12 @@ export function createDeviceGatewayCoreChannelClient(options = {}) {
},
});
connection.session = session;
connection.connectTimer = setTimeout(() => {
failConnection(connection, new Error(
"device_gateway_core_channel_connect_timeout",
));
}, config.connectTimeoutMs);
connection.connectTimer.unref?.();
session.once("error", (error) => failConnection(connection, error));
session.once("close", () => closeConnection(connection, true));
session.once("connect", () => {
@@ -250,6 +258,8 @@ export function createDeviceGatewayCoreChannelClient(options = {}) {
correlationId: envelope.correlationId,
});
connection.ready = true;
clearTimeout(connection.connectTimer);
connection.connectTimer = null;
reconnectAttempt = 0;
totalChannelsAccepted += 1;
lastErrorCode = null;
@@ -403,6 +413,8 @@ export function createDeviceGatewayCoreChannelClient(options = {}) {
function closeConnection(connection, reconnect) {
if (connection.closed) return;
connection.closed = true;
clearTimeout(connection.connectTimer);
connection.connectTimer = null;
clearInterval(connection.heartbeatTimer);
connection.heartbeatTimer = null;
connection.sessionChains.clear();
@@ -506,6 +518,13 @@ function normalizeConfig(options) {
acceptMessage: options.acceptMessage,
keepaliveMs,
deadPeerMs,
connectTimeoutMs: normalizeInteger(
options.connectTimeoutMs,
10,
120_000,
DEFAULT_CONNECT_TIMEOUT_MS,
"connect_timeout",
),
reconnectMinimumMs,
reconnectMaximumMs,
maxEnvelopeBytes: normalizeInteger(