Skip to content

getaddrinfo ENOTFOUND api.telegram.org #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sinneren opened this issue Apr 2, 2016 · 12 comments
Closed

getaddrinfo ENOTFOUND api.telegram.org #99

sinneren opened this issue Apr 2, 2016 · 12 comments

Comments

@sinneren
Copy link

sinneren commented Apr 2, 2016

Unhandled rejection Error: getaddrinfo ENOTFOUND api.telegram.org api.telegram.org:443
    at errnoException (dns.js:26:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

This error every day. I think it's because long plain. Maybe add live reload when exception?

@Orel2888
Copy link

This problem makes the OS reboot

@GochoMugo
Copy link
Collaborator

Possible fixes:

  • Upgrade your Node.js version (may overcome this error)
  • Flush your DNS
  • Reboot your machine (SO answer)

Related issues:

Please provide us with feedback.

@gtrias
Copy link

gtrias commented Dec 21, 2016

I'm having a similar issue:

"node-telegram-bot-api": "^0.24.0",
npm -v 4.0.5
node -v v7.2.1

The nodejs application is running inside docker container, but it used to work nice until started raising this errors..

Unhandled rejection RequestError: Error: getaddrinfo ENOTFOUND api.telegram.org api.telegram.org:443
    at new RequestError (/app/node_modules/request-promise/lib/errors.js:11:15)
    at Request.RP$callback [as _callback] (/app/node_modules/request-promise/lib/rp.js:60:32)
    at self.callback (/app/node_modules/request/request.js:186:22)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.onRequestError (/app/node_modules/request/request.js:845:8)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at TLSSocket.socketErrorListener (_http_client.js:309:9)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at connectErrorNT (net.js:1025:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

@dianjuar
Copy link

My bot is inside a Docker, I just stopped it and start again and everything was ok.

@Mrs-Feathers
Copy link

i have this issue all the time. restarting it does nothing because since i've got the latest version of node.js it completely shuts node down and the container goes down, so its constantly restarting all the time. network is bridged so it does have internet just fine. its its own container so dns cache shouldn't even be a thing since containers are cleared upon reboot.

@techieshark
Copy link

@dianjuar @MothGirlMusic not sure if you sorted your issue, but sometimes this ENOTFOUND issue is due to the underlying system not finding an IPv6 address for the host.

Some people report here adding family: 4 to the request() options does the trick (forces it to look for the IPv4 address, which should be findable).

It looks like request() options can be passed (see "request.options" on this page):

https://github.com/yagop/node-telegram-bot-api/blob/0b8ca03b54ac3361c2f656e2fa23c0e4423e49e5/doc/api.md#new-telegrambottoken-options

@melroy89
Copy link
Contributor

It's actually still not solved after 6 years

@almgwary
Copy link

any updates ?

@almgwary
Copy link

if you are using docker try to restart it, it works fine with me after restarting docker service

systemctl restart docker

@melroy89
Copy link
Contributor

melroy89 commented Jul 14, 2022

I also get sometimes getaddrinfo EAI_AGAIN api.telegram.org, often after a system reboot. And yes my DNS resolver is correctly configured.

My guess is that Docker is actually starting-up faster the Docker container than my system network / DNS resolver is ready to handle the requests. Something like that.

My bet is that my systemd is missing requires network dependency (see: Requires:) in the Docker service file:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

Although I see that containerd.service requires network.target as dependency. Maybe this isn't enough or on the wrong level or it should use network-online.target instead of network.target? Or After=network-online.target Wants=network-online.target or maybe better: After=nss-lookup.target should be added.

Restarting the specific docker container manually always fixes the issue.

@melroy89
Copy link
Contributor

melroy89 commented Jan 7, 2023

I already have a error handling, but it will not catch this getaddrinfo issue (so this code snipped will NOT help you):

telegramBot.on('error', (error) => {
})

Looking at the error traces, I suspect the request-promise package that throws this error. Which is used by in the internal function _request().

Meaning you need to try/catch .catch((error) => { ...} on all methods of this Telegram nodejs bot, including but not limited to: getUpdates(), setWebHook(), getWebHookInfo(), sendMessage(), sendPhoto(), sendAudio(), sendDocument(), sendVideo(), sendAnimation(), sendVoice(), sendXXXXYYYY(). Well, basically all set and get methods.

Once you catched the getaddrinfo error, you can maybe set a global state in an error state. Add a health check to Docker, so Docker will automatically restart the Docker image to try again. Most likely this will be the best solution, since after a server reboot the Docker container is started before the DNS is ready. Restarting the Docker container only once would resolve the error for now.

@yagop Ideally the node-telegram-bot-api code should be robust for this error and have built-in a retry mechanism. So the bot doesn't completely fail and stop working if this issue triggered only once.

Should we update the example code as well in your README? So developers have .catch((error) => console.error(error)) error handling by default on your setters& getters? This prevent the code from halting.

@Manikantkr-1004
Copy link

I have installed telegraf npm package and express and lot of other stuffs, but the issue is when i am running my server then i am getting this error in my terminal ->

FetchError: request to https://api.telegram.org/bot7031915653:[REDACTED]/getMe failed, reason: getaddrinfo ENOTFOUND api.telegram.org
at ClientRequest. (C:\Users\shash\OneDrive\Desktop\My_bot\node_modules\node-fetch\lib\index.js:1501:11)
at ClientRequest.emit (node:events:518:28)
at TLSSocket.socketErrorListener (node:_http_client:495:9)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ENOTFOUND',
code: 'ENOTFOUND'
}

My node version is 20.11.0
My npm version is 10.2.4

If you any guys has solutions of it, please reply here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests