botgram / shell-bot

:robot: Telegram bot that executes commands and sends the live output
GNU General Public License v3.0
787 stars 493 forks source link

crashing #1

Open tazhate opened 6 years ago

tazhate commented 6 years ago

events.js:160 throw er; // Unhandled 'error' event ^ NetworkError: Error: connect ETIMEDOUT 149.154.167.197:443 at NetworkError.Error (native) at new NetworkError (/root/shell-bot/node_modules/botgram/lib/bot.js:21:20) at ClientRequest.handleResponse (/root/shell-bot/node_modules/botgram/lib/bot.js:129:24) at emitOne (events.js:96:13) at ClientRequest.emit (events.js:188:7) at TLSSocket.socketErrorListener (_http_client.js:310:9) at emitOne (events.js:96:13) at TLSSocket.emit (events.js:188:7) at emitErrorNT (net.js:1277:8) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)

mildsunrise commented 6 years ago

This literally means the bot can't connect to Telegram. Do you still get this error? Is internet working from that machine? Verify your network settings.

Also, please post the output of curl -v https://api.telegram.org (again, in that same machine)

tazhate commented 6 years ago

I know it, but why it is crashing? I think that bot should try to reconnect instead of crash :) Sometimes servers get lost of connectivity, so bot should be able to handle this kind of situations.

mildsunrise commented 6 years ago

This is true. The latest (unreleased ATM) Botgram retries most requests without failing, so as long as you're not using your bot when Telegram servers crash, it will keep running.

However, there's still a lot of corner situations that I don't know how to handle (Telegram API unreachable, message limit exceeded, ...) so I always recomment running the bot with a respawner.

3guboff commented 6 years ago

Hello, same crash:

2017-11-19 20:55 +03:00: NetworkError: Error: connect ECONNREFUSED 149.154.167.197:443
    at new NetworkError (/home/services/telegram-shell/current/node_modules/botgram/lib/bot.js:21:20)
    at ClientRequest.handleResponse (/home/services/telegram-shell/current/node_modules/botgram/lib/bot.js:129:24)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
mildsunrise commented 6 years ago

That's probably because your Internet is momentarily failing, or Telegram's API is down (which happens a lot lately). If you get NetworkError: API response not in JSON then Telegram is answering requests with 502 errors:

HTTP/1.1 502 Bad Gateway
Server: nginx/1.12.2
Date: Fri, 08 Dec 2017 01:12:17 GMT
Content-Type: text/html
Content-Length: 173
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>

The last (still unreleased) version of Botgram will avoid most crashes when any of these issues happen. But I'll still recommend using a respawner.