Skip to content

Error: socket hang up #74

Closed
Closed
@askucher

Description

@askucher

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 }

Activity

ikerya

ikerya commented on Aug 7, 2020

@ikerya

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

mast commented on Aug 7, 2020

@mast
Owner

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

ikerya commented on Aug 8, 2020

@ikerya

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

mast commented on Aug 9, 2020

@mast
Owner

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

added a commit that references this issue on Aug 10, 2020
mast

mast commented on Aug 10, 2020

@mast
Owner

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

ergcode commented on Dec 2, 2020

@ergcode

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'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mast@askucher@ergcode@ikerya

        Issue actions

          Error: socket hang up · Issue #74 · mast/telegram-bot-api