tdlib / telegram-bot-api

Telegram Bot API server
https://core.telegram.org/bots
Boost Software License 1.0
2.94k stars 569 forks source link

request Timeout #563

Closed RealYukiSan closed 3 months ago

RealYukiSan commented 3 months ago

I've test my internet connectivity by running this command:

curl "https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \
"https://api.telegram.org/bot<token>/getUpdates" \

and I not see timeout using curl, but when it uses fetch, sometimes timeout arises, how to fix the timeout problem in fetch nodejs? I also tried fetch with keepAlive and timeout but not work:

const param = `timeout=300&offset=${last_update}`;
const response = await fetch(`${process.env.BASE_URL}/getUpdates?${param}`, { keepalive: true, signal: AbortSignal.timeout(1000 * 300) }).then(res => res.json())
levlam commented 3 months ago

You must set request timeout bigger than timeout parameter of the request.

RealYukiSan commented 3 months ago

The situation remains unchanged even when I change the timeout value:

const param = `timeout=150&offset=${last_update}`;
const response = await fetch(`${process.env.BASE_URL}/getUpdates?${param}`, { keepalive: true, signal: AbortSignal.timeout(1000 * 200) }).then(res => res.json())
levlam commented 3 months ago

Check how much time has passed between request start and response. If it is 200+ seconds, then there were a network issue, which is normal.

RealYukiSan commented 3 months ago

thanks for the help!