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

TIMEOUT I'm using version 2.6.13 #302

Open
wind-hx opened this issue Apr 20, 2022 · 17 comments
Open

TIMEOUT I'm using version 2.6.13 #302

wind-hx opened this issue Apr 20, 2022 · 17 comments

Comments

@wind-hx
Copy link

wind-hx commented Apr 20, 2022

Version 2.6.13 the same problem occurs, A large number of timeouts will occur in the program running for a long time, which will eventually lead to 100% of the CPU and the server cannot be used.
image

image

@wind-hx wind-hx changed the title can't reconnect Error: TIMEOUT I'm using version 2.6.11 can't reconnect Error: TIMEOUT I'm using version 2.6.13 Apr 20, 2022
@wind-hx
Copy link
Author

wind-hx commented Apr 20, 2022

cpu-profile-6942-20220420-174229.cpuprofile.zip
This is the result of node.js cpu analysis

@painor
Copy link
Member

painor commented Apr 20, 2022

is that the only code you're using? can you send a small reproducible code ?

@wind-hx
Copy link
Author

wind-hx commented Apr 21, 2022

is that the only code you're using? can you send a small reproducible code ?

Sorry, I can't reproduce this problem locally, but I can provide a development environment server, you can connect to the development environment server to view this error

@wind-hx
Copy link
Author

wind-hx commented Apr 21, 2022

is that the only code you're using? can you send a small reproducible code ?

This problem has been bothering me for a long time, I hope you can provide telegram contact information, I will send you the ip of the development environment server, you can connect to the server to see the log

@wind-hx
Copy link
Author

wind-hx commented Apr 21, 2022

is that the only code you're using? can you send a small reproducible code ?

timeout is not a network connection timeout, Some connections will have a timeout, but there is no problem with the network

Error: Cannot send requests while disconnected. You need to call .connect()
    at MTProtoSender.send (/root/telegram-transport/node_modules/telegram/network/MTProtoSender.js:197:19)
    at /root/telegram-transport/node_modules/telegram/client/updates.js:163:47
    at attempts (/root/telegram-transport/node_modules/telegram/client/updates.js:203:26)
    at Object._updateLoop (/root/telegram-transport/node_modules/telegram/client/updates.js:162:13)
Error: TIMEOUT
    at /root/telegram-transport/node_modules/telegram/client/updates.js:218:55
    at attempts (/root/telegram-transport/node_modules/telegram/client/updates.js:203:20)
    at Object._updateLoop (/root/telegram-transport/node_modules/telegram/client/updates.js:162:13)
Error: TIMEOUT
    at /root/telegram-transport/node_modules/telegram/client/updates.js:218:55
    at attempts (/root/telegram-transport/node_modules/telegram/client/updates.js:203:20)
    at Object._updateLoop (/root/telegram-transport/node_modules/telegram/client/updates.js:162:13)
Error: Cannot send requests while disconnected. You need to call .connect()
    at MTProtoSender.send (/root/telegram-transport/node_modules/telegram/network/MTProtoSender.js:197:19)
    at /root/telegram-transport/node_modules/telegram/client/updates.js:163:47
    at attempts (/root/telegram-transport/node_modules/telegram/client/updates.js:203:26)
    at runMicrotasks (<anonymous>)
    at runNextTicks (internal/process/task_queues.js:60:5)
    at listOnTimeout (internal/timers.js:526:9)
    at processTimers (internal/timers.js:500:7)
    at Object._updateLoop (/root/telegram-transport/node_modules/telegram/client/updates.js:162:13)
Error: TIMEOUT
    at /root/telegram-transport/node_modules/telegram/client/updates.js:218:55
    at runMicrotasks (<anonymous>)
    at runNextTicks (internal/process/task_queues.js:60:5)
    at listOnTimeout (internal/timers.js:526:9)
    at processTimers (internal/timers.js:500:7)
    at attempts (/root/telegram-transport/node_modules/telegram/client/updates.js:203:20)
    at Object._updateLoop (/root/telegram-transport/node_modules/telegram/client/updates.js:162:13)
Error: Cannot send requests while disconnected. You need to call .connect()
    at MTProtoSender.send (/root/telegram-transport/node_modules/telegram/network/MTProtoSender.js:197:19)
    at /root/telegram-transport/node_modules/telegram/client/updates.js:163:47
    at attempts (/root/telegram-transport/node_modules/telegram/client/updates.js:203:26)
    at Object._updateLoop (/root/telegram-transport/node_modules/telegram/client/updates.js:162:13)

sleep(ms).then(() => Promise.reject(new Error("TIMEOUT"))),

@wind-hx wind-hx changed the title can't reconnect Error: TIMEOUT I'm using version 2.6.13 TIMEOUT I'm using version 2.6.13 Apr 21, 2022
@painor
Copy link
Member

painor commented Apr 21, 2022

You can find me in https://t.me/gramjschat

@MichaelCasaDev
Copy link

There are updates on this topic?

@painor
Copy link
Member

painor commented May 9, 2022

There are updates on this topic?

The latest version should have had some fixes for this.

@emiliocr90
Copy link

emiliocr90 commented Oct 18, 2023

Hi guys. I'm using version 2.17.4 and still getting timout on error log.

Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
at attempts (/home/user/node_modules/telegram/client/updates.js:228:20)
at _updateLoop (/home/user/node_modules/telegram/client/updates.js:180:17)
Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
at attempts (/home/user/node_modules/telegram/client/updates.js:228:20)
at _updateLoop (/home/user/node_modules/telegram/client/updates.js:180:17)
Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
at attempts (/home/user/node_modules/telegram/client/updates.js:228:20)
at _updateLoop (/home/user/node_modules/telegram/client/updates.js:180:17)
Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
at attempts (/home/user/node_modules/telegram/client/updates.js:228:20)
at _updateLoop (/home/user/node_modules/telegram/client/updates.js:180:17)
Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85
at runNextTicks (node:internal/process/task_queues:60:5)
at listOnTimeout (node:internal/timers:540:9)
at processTimers (node:internal/timers:514:7)
at attempts (/home/user/node_modules/telegram/client/updates.js:228:20)
at _updateLoop (/home/user/node_modules/telegram/client/updates.js:180:17)
Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85
at attempts (/home/user/node_modules/telegram/client/updates.js:228:20)
at _updateLoop (/home/user/node_modules/telegram/client/updates.js:180:17)

@emiliocr90
Copy link

emiliocr90 commented Oct 18, 2023

my code:

async main(): Promise<void>
    {       
    const sessionTxt: string = fs.readFileSync(__dirname + '/data/session.txt', {encoding: 'utf-8'}),
              stringSession: StringSession = new StringSession(sessionTxt),
              client: TelegramClient = new TelegramClient(stringSession, *, '*', {connectionRetries: 10});

        client.setLogLevel(LogLevel.ERROR);
        await client.start(
        {
            phoneNumber: '*', 
            phoneCode: async () => await input.text('Code:'), 
            onError: (err) => console.error(err)
        });
        fs.writeFileSync(__dirname + '/data/session.txt', (<StringSession> client.session).save(), {encoding: 'utf-8', flag: 'w'});

        do
        {
            client.connect();
            await sleep(2000);
            if(!client.connected) fs.writeFileSync(__dirname + '/logs/connect_log', new Date() + ' Not connected' + '<br>\n<br>\n', {encoding: 'utf-8', flag: 'a'});
        }
        while(!client.connected);

        let lastMessages: Api.TypeMessage[], lastMessage: Api.Message;

        lastMessages = (<Api.messages.Messages> await client.invoke(new Api.messages.GetHistory(
        {
            peer: <bigInt.BigInteger> (<unknown> -1001717037581),
            limit: 20
        }))).messages;

        lastMessages.forEach((msg: Api.Message) =>
        {
            if(msg.replyTo === null)
                if(msg.message && msg.message.startsWith('🔥'))
                {
                    if((Date.now() - msg.date*1000) < 120000)
                    {
                        const lines: string[] = msg.message.split('\n\n'),
                              config: any = JSON.parse(fs.readFileSync(__dirname + '/data/config.json', {encoding: 'utf-8'})),
                              excluded: boolean = config.excluded;
                              
                        if(!excluded) this.doSomething();
                        
                        fs.writeFileSync(__dirname + '/logs/telegram_log', new Date() + `\n ${msg.message} \n\n`, {encoding: 'utf-8', flag: 'a'});
                    }                    
                }
        });

        client.disconnect();
    }

this code is executed every minute by a cronjob.

@SJPiran
Copy link

SJPiran commented Oct 21, 2023

my code:

async main(): Promise<void>
    {       
    const sessionTxt: string = fs.readFileSync(__dirname + '/data/session.txt', {encoding: 'utf-8'}),
              stringSession: StringSession = new StringSession(sessionTxt),
              client: TelegramClient = new TelegramClient(stringSession, *, '*', {connectionRetries: 10});

        client.setLogLevel(LogLevel.ERROR);
        await client.start(
        {
            phoneNumber: '*', 
            phoneCode: async () => await input.text('Code:'), 
            onError: (err) => console.error(err)
        });
        fs.writeFileSync(__dirname + '/data/session.txt', (<StringSession> client.session).save(), {encoding: 'utf-8', flag: 'w'});

        do
        {
            client.connect();
            await sleep(2000);
            if(!client.connected) fs.writeFileSync(__dirname + '/logs/connect_log', new Date() + ' Not connected' + '<br>\n<br>\n', {encoding: 'utf-8', flag: 'a'});
        }
        while(!client.connected);

        let lastMessages: Api.TypeMessage[], lastMessage: Api.Message;

        lastMessages = (<Api.messages.Messages> await client.invoke(new Api.messages.GetHistory(
        {
            peer: <bigInt.BigInteger> (<unknown> -1001717037581),
            limit: 20
        }))).messages;

        lastMessages.forEach((msg: Api.Message) =>
        {
            if(msg.replyTo === null)
                if(msg.message && msg.message.startsWith('🔥'))
                {
                    if((Date.now() - msg.date*1000) < 120000)
                    {
                        const lines: string[] = msg.message.split('\n\n'),
                              config: any = JSON.parse(fs.readFileSync(__dirname + '/data/config.json', {encoding: 'utf-8'})),
                              excluded: boolean = config.excluded;
                              
                        if(!excluded) this.doSomething();
                        
                        fs.writeFileSync(__dirname + '/logs/telegram_log', new Date() + `\n ${msg.message} \n\n`, {encoding: 'utf-8', flag: 'a'});
                    }                    
                }
        });

        client.disconnect();
    }

this code is executed every minute by a cronjob.

I'd have the same problem, I think this is a Gram js bug, and I hope that will be fixed in the next version

@SJPiran
Copy link

SJPiran commented Oct 21, 2023

for this error (Error: TIMEOUT
at /home/user/node_modules/telegram/client/updates.js:244:85)

go to this file (updates.js) line 244 and remove await before the promise. enjoy!

@MichaelCasaDev
Copy link

go to this file (updates.js) line 244 and remove await before the promise. enjoy!

I don't think is good for production this...

@davie-robertson
Copy link

I've upgraded to 2.19.10 and I'm now facing this, I don't think I had the issue in 2.17.4

@0xluc
Copy link

0xluc commented May 7, 2024

Is there any way to avoid this error being logged?

@binamralamsal
Copy link

binamralamsal commented May 28, 2024

I am also facing same issue on v2.20.15
Edit: Same problem even on v2.21.2

@sapn1s
Copy link

sapn1s commented Jun 18, 2024

For anyone having Error: TIMEOUT spam problem:
(For me it occurs because I disconnect client without destroying it, so I can later connect using the same client)

You can disable all logs using client.setLogLevel("none");

And to actually be able to handle the errors instead of only getting them spammed, define your logger function and assign it to the client:

// Define the error handler function:
async function errorHandler(error) {
    if (error.message && error.message == 'TIMEOUT') {
        //Do nothing, as this error does not make sense to appear while keeping the client disconnected
    } else {
        console.error(`Error occurred for API ID ${this.apiId}:`, error);
        // Handle other types of errors
    }}
    
 //Assign this handler to client: 
client._errorHandler = errorHandler

You can not keep info/warn logs with something like client.setLogLevel("info"); because logger is defined as levels: [ 'error', 'warn', 'info', 'debug' ] and whatever your choice is, it will log everything to the left in the array for the level of your choice.

So to keep info/warning logs, you need to re-define the log levels array:

client._log.levels = ['warn', 'info', 'error','debug' ];
client.setLogLevel("info");

Thus, the result is that you still get all the other logs while errors can actually be handled.

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