gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

TIMEOUT I'm using version 2.6.13

Open wind-hx opened this issue 2 years ago • 17 comments

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 avatar Apr 20 '22 03:04 wind-hx

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

wind-hx avatar Apr 20 '22 09:04 wind-hx

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

painor avatar Apr 20 '22 16:04 painor

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 avatar Apr 21 '22 04:04 wind-hx

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 avatar Apr 21 '22 04:04 wind-hx

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)

https://github.com/gram-js/gramjs/blob/b6b46c8699d7ce5e2290cabf0a5cdc0578dbecc8/gramjs/client/updates.ts#L258

wind-hx avatar Apr 21 '22 07:04 wind-hx

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

painor avatar Apr 21 '22 10:04 painor

There are updates on this topic?

MichaelCasaDev avatar May 09 '22 07:05 MichaelCasaDev

There are updates on this topic?

The latest version should have had some fixes for this.

painor avatar May 09 '22 09:05 painor

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 avatar Oct 18 '23 08:10 emiliocr90

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.

emiliocr90 avatar Oct 18 '23 08:10 emiliocr90

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 avatar Oct 21 '23 17:10 SJPiran

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!

SJPiran avatar Oct 21 '23 19:10 SJPiran

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

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

MichaelCasaDev avatar Oct 25 '23 14:10 MichaelCasaDev

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

davie-robertson avatar Jan 21 '24 22:01 davie-robertson