From 357503ee2fe2a316b4483b99d6da63d3def82ba3 Mon Sep 17 00:00:00 2001 From: shats Date: Wed, 18 Feb 2026 16:01:21 +0700 Subject: [PATCH] fix(NetworkMapScheduler): increase speed test request timeout to 5 minutes and improve error logging for aborted requests --- backend/services/networkMapScheduler.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/services/networkMapScheduler.js b/backend/services/networkMapScheduler.js index e588d82..7b5877b 100644 --- a/backend/services/networkMapScheduler.js +++ b/backend/services/networkMapScheduler.js @@ -251,12 +251,16 @@ async function runJob(opts) { } if (runSpeedTest) { + // Таймаут запроса: замер может долго идти на медленных каналах (download + upload по durationSeconds каждый) + const SPEED_TEST_REQUEST_MS = 300000; // 5 мин const withSpeed = connections.filter((c) => c.speedTestServerId && c.interfaceName); const speedTasks = withSpeed.map((c) => async () => { const key = speedKey(c.fromKey, c.toKey); const server = servers.find((s) => (s.id || s.dns || s.ip) === c.speedTestServerId); const serverLabel = server ? (server.dns || server.ip || server.id) : c.speedTestServerId; const speedLabel = `${serverLabel} / ${c.interfaceName}`; + const ac = new AbortController(); + const timeoutId = setTimeout(() => ac.abort(), SPEED_TEST_REQUEST_MS); try { const res = await fetch(`${baseUrl}/api/mikrotik/speed-test`, { method: 'POST', @@ -266,12 +270,9 @@ async function runJob(opts) { interfaceName: c.interfaceName, forceRefresh: true, }), - signal: (() => { - const ac = new AbortController(); - setTimeout(() => ac.abort(), 120000); - return ac.signal; - })(), + signal: ac.signal, }); + clearTimeout(timeoutId); const data = await res.json().catch(() => ({})); if (data?.ok && (data.tcpDownloadBps != null || data.tcpUploadBps != null)) { speedMap[key] = { @@ -290,8 +291,11 @@ async function runJob(opts) { log(`Скорость ${speedLabel}: ${speedErr}`); return null; } catch (e) { + clearTimeout(timeoutId); speedMap[key] = null; - log(`Скорость ${speedLabel}: ошибка ${e?.message || e}`); + const msg = e?.message || e; + const isAbort = String(msg).toLowerCase().includes('abort'); + log(`Скорость ${speedLabel}: ошибка ${isAbort ? 'таймаут или отмена запроса' : msg}`); return null; } });