fix(NetworkMapScheduler): increase speed test request timeout to 5 minutes and improve error logging for aborted requests
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m44s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m44s
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user