fix gateway restart handshake timeout (#689)

Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
Lingxuan Zuo
2026-03-30 16:09:23 +08:00
committed by GitHub
Unverified
parent ef3cf64484
commit e988258c59
2 changed files with 193 additions and 2 deletions

View File

@@ -8,6 +8,9 @@ import {
} from '../utils/device-identity';
import { logger } from '../utils/logger';
export const GATEWAY_CHALLENGE_TIMEOUT_MS = 10_000;
export const GATEWAY_CONNECT_HANDSHAKE_TIMEOUT_MS = 20_000;
export async function probeGatewayReady(
port: number,
timeoutMs = 1500,
@@ -169,8 +172,12 @@ export async function connectGatewaySocket(options: {
onHandshakeComplete: (ws: WebSocket) => void;
onMessage: (message: unknown) => void;
onCloseAfterHandshake: () => void;
challengeTimeoutMs?: number;
connectTimeoutMs?: number;
}): Promise<WebSocket> {
logger.debug(`Connecting Gateway WebSocket (ws://localhost:${options.port}/ws)`);
const challengeTimeoutMs = options.challengeTimeoutMs ?? GATEWAY_CHALLENGE_TIMEOUT_MS;
const connectTimeoutMs = options.connectTimeoutMs ?? GATEWAY_CONNECT_HANDSHAKE_TIMEOUT_MS;
return await new Promise<WebSocket>((resolve, reject) => {
const wsUrl = `ws://localhost:${options.port}/ws`;
@@ -234,7 +241,7 @@ export async function connectGatewaySocket(options: {
ws.close();
rejectOnce(new Error('Connect handshake timeout'));
}
}, 10000);
}, connectTimeoutMs);
handshakeTimeout = requestTimeout;
options.pendingRequests.set(connectId, {
@@ -258,7 +265,7 @@ export async function connectGatewaySocket(options: {
ws.close();
rejectOnce(new Error('Timed out waiting for connect.challenge from Gateway'));
}
}, 10000);
}, challengeTimeoutMs);
ws.on('open', () => {
logger.debug('Gateway WebSocket opened, waiting for connect.challenge...');