Skip to content
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

Bot stops randomly #101

Open
LBreda opened this issue Aug 5, 2016 · 21 comments
Open

Bot stops randomly #101

LBreda opened this issue Aug 5, 2016 · 21 comments

Comments

@LBreda
Copy link

LBreda commented Aug 5, 2016

Every now and then, the bot stops working (without crashing).

The forever log is the same every time: http://pastebin.com/0Cwhbe6i

@TemaSM
Copy link

TemaSM commented Aug 6, 2016

Seems to be that when telegram-node-bot tries to getUpdates, your network connection closed or (lower probability) Telegram can't answer on domain api.telegram.org.
I'm pretty sure, that you have problem with internet connection or DNS server of your provider/machine, because Node.js native module dns.js fires this Error:

No network connection. Error: Error: getaddrinfo ENOTFOUND api.telegram.org api.telegram.org:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)

and that's why module tiny_request can't receive appropriate JSON:

api request error: Body: undefined
Error: SyntaxError: Unexpected token < in JSON at position 0
    at Object.parse (native)
    at IncomingMessage.response.on.e (/node_modules/tiny_request/lib/network.js:68:38)

Also pls see nodejs/node-v0.x-archive#5488
So, that's not fault of telegram-node-bot 😏

@LBreda
Copy link
Author

LBreda commented Aug 6, 2016

The error is obviously not generated by telegram-node-bot, but telegram-node-bot does not correctly manage the error.

I don't expect the bot to stop getting updates after a single getUpdates fails.

@TemaSM
Copy link

TemaSM commented Aug 6, 2016

How about to manually find out what wrong is going on? Try to use only tiny_request module to make request to api.telegram.org and please submit every log to this issue.
Maybe in near future I will make PR with fix for better handling this Error.

@LBreda
Copy link
Author

LBreda commented Aug 6, 2016

I'm working to make my bot work well again in my free time. Still, I had to open this issue here, to enlight the bad behavior of this library.

If you'll work on it I'll be grateful! I haven't explored the version 3 internals yet.

@TemaSM
Copy link

TemaSM commented Aug 6, 2016

So, I gonna try to reproduce the same issue as you have, and then find out how to fix or just handle this Error.
Please stay tuned, I will give you a link for forked repo, where I will submit commits with fix, then you may just npm install name/repo in a while instead just npm update, cause author of this repo doesn't maintain it so often 😔

@kamikazechaser
Copy link
Contributor

This is a Telegram API error. Affecting everyone. Confirmed.

@TemaSM
Copy link

TemaSM commented Aug 6, 2016

Thanks for info, but anyway we should implement error handling 😅

@LBreda
Copy link
Author

LBreda commented Aug 15, 2016

Any news?

@kamikazechaser
Copy link
Contributor

Upgrade both node and the module to the latest versions.

@VitaliyR
Copy link

I'm already on v6@latest and its reproducing

@frengkys
Copy link

hey, can i get message id and chat id user with bot,
i wanna use forwardMessage method but don't know how to get the parameter...

@TemaSM
Copy link

TemaSM commented Aug 25, 2016

@frengkys Please read documentation/API here

@frengkys
Copy link

actually i am still reading it but dont know how to call it heheheh

@frengkys
Copy link

how to get what user send to the bot?
there is some method ?

im just wanna console.log(whatUserSend) on my command prompt

@TemaSM
Copy link

TemaSM commented Aug 29, 2016

@frengkys Welcome to Gitter chat: telegram-node-bot - answered you here to prevent spam in Issues.

@Naltox
Copy link
Owner

Naltox commented Sep 9, 2016

Hey guys, at this moment we have:

  • retry requests on any network error code
  • retry requests when we cant parse Json (because of error in tg api)
  • retry on 500 code
  • reject on any other errors

Dont know what else to add, any ideas?

@Naltox
Copy link
Owner

Naltox commented Sep 9, 2016

p.s. I will publish soon v4.0 with webhooks, hope that helps

@sosnovsky
Copy link

@Naltox how is v4.0 is going? :)

@dutu
Copy link

dutu commented Sep 28, 2016

using version 3.0.12 . Bot unresponsive after this error:

Sep 27 12:02:02  app/web.1:  [error]    
Sep 27 12:02:02  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:02  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:02  app/web.1:      at Object.parse (native) 
Sep 27 12:02:02  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:02  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:02  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:02  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:02  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:02  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:03  app/web.1:  [log]    
Sep 27 12:02:03  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:03  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:03  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:03  app/web.1:    _multipart: undefined } 
Sep 27 12:02:03  app/web.1:  [error]    
Sep 27 12:02:03  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:03  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:03  app/web.1:      at Object.parse (native) 
Sep 27 12:02:03  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:03  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:03  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:03  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:03  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:03  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:04  app/web.1:  [error]    
Sep 27 12:02:04  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:04  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:04  app/web.1:      at Object.parse (native) 
Sep 27 12:02:04  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:04  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:04  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:04  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:04  app/web.1:  [log]    
Sep 27 12:02:04  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:04  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:04  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:04  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:04  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:04  app/web.1:    _multipart: undefined } 
Sep 27 12:02:06  app/web.1:  [log]    
Sep 27 12:02:06  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:06  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:06  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:06  app/web.1:    _multipart: undefined } 
Sep 27 12:02:06  app/web.1:  [error]    
Sep 27 12:02:06  app/web.1:  api request error: Telegram returned some html instead of json. Body: undefined 
Sep 27 12:02:06  app/web.1:  Error: SyntaxError: Unexpected token < in JSON at position 0 
Sep 27 12:02:06  app/web.1:      at Object.parse (native) 
Sep 27 12:02:06  app/web.1:      at IncomingMessage.response.on.e (/app/node_modules/tiny_request/lib/network.js:68:38) 
Sep 27 12:02:06  app/web.1:      at emitNone (events.js:91:20) 
Sep 27 12:02:06  app/web.1:      at IncomingMessage.emit (events.js:185:7) 
Sep 27 12:02:06  app/web.1:      at endReadableNT (_stream_readable.js:934:12) 
Sep 27 12:02:06  app/web.1:      at _combinedTickCallback (internal/process/next_tick.js:74:11) 
Sep 27 12:02:06  app/web.1:      at process._tickCallback (internal/process/next_tick.js:98:9) 
Sep 27 12:02:07  app/web.1:  [log]    
Sep 27 12:02:07  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:02:07  app/web.1:    _method: 'getUpdates', 
Sep 27 12:02:07  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:02:07  app/web.1:    _multipart: undefined } 
Sep 27 12:14:41  app/web.1:  [warn]    
Sep 27 12:14:41  app/web.1:  Got Internal server error from Telegram. Body: { ok: false, 
Sep 27 12:14:41  app/web.1:    error_code: 500, 
Sep 27 12:14:41  app/web.1:    description: 'Internal server error: restart' } 
Sep 27 12:14:42  app/web.1:  [log]    
Sep 27 12:14:42  app/web.1:  Retry request TelegramApiRequest { 
Sep 27 12:14:42  app/web.1:    _method: 'getUpdates', 
Sep 27 12:14:42  app/web.1:    _params: { timeout: 50, offset: 0 }, 
Sep 27 12:14:42  app/web.1:    _multipart: undefined } 
Sep 27 12:14:42  app/web.1:  [warn]    
Sep 27 12:14:42  app/web.1:  Api error: Body: { ok: false, 
Sep 27 12:14:42  app/web.1:    error_code: 429, 
Sep 27 12:14:42  app/web.1:    description: 'Too Many Requests: retry after 5', 
Sep 27 12:14:42  app/web.1:    parameters: { retry_after: 5 } }

@chiu0602
Copy link
Contributor

Issue persists on v4 API. Does the code have retry mechanism for network disconnection? And when the bot not response to commands, the web admin page also cannot be reached.

@kamikazechaser
Copy link
Contributor

I usually force keep the bot alive by handling any uncaught exceptions!

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

No branches or pull requests

9 participants