I am currently developing a program that utilizes long polling to perform periodic fetches.
However, I am frequently encountering timeout errors during the fetch process, despite having a stable internet connection. I have thoroughly verified that my internet connection is functioning properly, and the issue persists.
I have already tried the following solutions, but the problem still persists:
- increase timeout by
signal: AbortSignal.timeout(1000 * 200) - use
keepAliveoption - increase timeout from query string on telegram api
- fetch per 2 second instead of miliseconds
Here are some additional details that may be relevant:
Test by speedtest:
Idle Latency: 20.14 ms (jitter: 2.87ms, low: 19.27ms, high: 29.80ms)
Download: 9.76 Mbps (data used: 11.5 MB)
522.78 ms (jitter: 88.34ms, low: 45.85ms, high: 1349.79ms)
Upload: 0.34 Mbps (data used: 597.3 kB)
2274.00 ms (jitter: 93.18ms, low: 186.00ms, high: 3920.09ms)
Packet Loss: 0.0%
Error log (actually it happens more than three times):
TypeError: fetch failed
at node:internal/deps/undici/undici:12443:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async handler (/home/user/control-center/start-service.js:15:22) {
cause: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1116:18)
at internalConnectMultiple (node:net:1184:5)
at Timeout.internalConnectMultipleTimeout (node:net:1707:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
TypeError: fetch failed
at node:internal/deps/undici/undici:12443:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async handler (/home/user/control-center/start-service.js:15:22) {
cause: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1116:18)
at internalConnectMultiple (node:net:1184:5)
at Timeout.internalConnectMultipleTimeout (node:net:1707:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
TypeError: fetch failed
at node:internal/deps/undici/undici:12443:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async handler (/home/user/control-center/start-service.js:15:22) {
cause: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1116:18)
at internalConnectMultiple (node:net:1184:5)
at Timeout.internalConnectMultipleTimeout (node:net:1707:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
The snippet code:
const param = `timeout=150&offset=${last_update}`;
const response = await fetch(`${process.env.BASE_URL}/getUpdates?${param}`, { keepalive: true }).then(res => res.json())
full code availabe on github repository