mast / telegram-bot-api

First Telegram Bot API node.js library
http://mast.github.io/telegram-bot-api/
MIT License
245 stars 65 forks source link

Error: socket hang up #74

Closed askucher closed 4 years ago

askucher commented 4 years ago

When bot gets this issue it does not react on any further commands. The simple restart of process helps.

Investigation: Have checked the code and figure out that it is trying to repeat the request later but it still fails

[TelegramBot]: Failed to get updates from Telegram servers
{ RequestError: Error: socket hang up
    at new RequestError (/root/workspace/node-app/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/root/workspace/velas-god/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/root/workspace/node-app/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/root/workspace/node-app/node_modules/request/request.js:185:22)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at Request.onRequestError (/root/workspace/node-app/node_modules/request/request.js:877:8)
    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._tickCallback (internal/process/next_tick.js:180:9)
  name: 'RequestError',
  message: 'Error: socket hang up',
  cause:
   { Error: socket hang up
    at TLSSocket.onHangUp (_tls_wrap.js:1137:19)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
     code: 'ECONNRESET',
     path: null,
     host: 'api.telegram.org',
     port: 443,
     localAddress: undefined },
  error:
   { Error: socket hang up
    at TLSSocket.onHangUp (_tls_wrap.js:1137:19)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
     code: 'ECONNRESET',
     path: null,
     host: 'api.telegram.org',
     port: 443,
     localAddress: undefined },
  options:
   { proxy: null,
     method: 'GET',
     json: true,
     formData: { timeout: 0, offset: 764361189, limit: 50 },
     uri: 'https://api.telegram.org/..../getUpdates',
     callback: [Function: RP$callback],
     transform: undefined,
     simple: true,
     resolveWithFullResponse: false,
     transform2xxOnly: false },
  response: undefined }
ikerya commented 4 years ago

The same here. I think, the issue isn't in his code. The problem has been appearing for the last week or two, approximately.

I have the same problem in different projects on different hostings, which are functioning in different countries.

Waiting for the fix. Thank you.

mast commented 4 years ago

Is there any special reason you use GetUpdates message provider instead of WebHook? GetUpdates method is issuing constant connections to Telegram servers even when there are no activity in your telegram bots/chats. Socket stays open until something happens, then messages are getting delivered and new connection is getting initiated. This works quite slow. It's not recommended for production envs and to be used during development/testing. WebHook thought works in the way, that telegram servers initiate connection to your bot when something is happening.

ikerya commented 4 years ago

For webhooks a domain is needed. So it's an inefficient way to create an independent bot.

But! If something doesn't work, it doesn't mean you should change the method... So no fixes..?

mast commented 4 years ago

Is this reproducible with latest version of library? message delivery mechanics were refactored in 2.0.

mast commented 4 years ago

Ok, I think I reproduced this problem and just delivered the fix. Checkout version 2.0.1. Please reopen this ticket if you are able to reproduce with 2.0.1

ergcode commented 3 years ago

I am sending two xlsx documents to two contacts.

// package.json
"node-telegram-bot-api": "^0.50.0",
// code
let telegramOptions = {
    polling: true,
};
const telegram = new telegramBot(config.telegram.token, telegramOptions);
let ids = [111,222];

(async () => {
    const document = fs.createReadStream(`./result.xlsx`);
    const fileOpts = {
        filename: `result.xlsx`,
        contentType: `application/octet-stream`,
    };
    for (let i = 0; i < ids.length; i++) {
        await telegram.sendDocument(ids[i], document, {}, fileOpts);
    }
})();

The file comes to the first contact, and displays an error for the next contacts.

2020-12-02 23:16:49 [1606951009815] | RequestError: Error: socket hang up
    at new RequestError (/root/bot/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/root/bot/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/root/bot/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/root/bot/node_modules/request/request.js:185:22)
    at Request.emit (events.js:327:22)
    at Request.onRequestError (/root/bot/node_modules/request/request.js:877:8)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketOnEnd (_http_client.js:493:9)
    at TLSSocket.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EFATAL'
}