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

Client disconnects after one request #62

Closed
maheshbansod opened this issue Mar 9, 2021 · 13 comments
Closed

Client disconnects after one request #62

maheshbansod opened this issue Mar 9, 2021 · 13 comments

Comments

@maheshbansod
Copy link

After making one raw request through gramjs, it went through and returned the correct response but a few seconds after that I got this error on the console:

{ Error: Invalid checksum (1241442304 when 1399867364 was expected). This packet should be skipped.
    at FullPacketCodec.<anonymous> (/home/null/apps/epic-light-bot/node_modules/telegram/dist/network/connection/TCPFull.js:53:23)
    at Generator.next (<anonymous>)
    at fulfilled (/home/null/apps/epic-light-bot/node_modules/telegram/dist/network/connection/TCPFull.js:5:58)
    at process._tickCallback (internal/process/next_tick.js:68:7) checksum: 1241442304, validChecksum: 1399867364 }

Any requests after this, result in an error saying it cannot send requests while disconnected:

Error: Cannot send requests while disconnected
    at MTProtoSender.send (/home/null/apps/epic-light-bot/node_modules/telegram/dist/network/MTProtoSender.js:199:19)
    at TelegramClient.<anonymous> (/home/null/apps/epic-light-bot/node_modules/telegram/dist/client/users.js:39:50)
    at Generator.next (<anonymous>)
    at fulfilled (/home/null/apps/epic-light-bot/node_modules/telegram/dist/client/users.js:5:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I'm not sure if I'm doing something wrong. Everything works well, when I do client.start again.

Also, is there a way to disable the [DEBUG] logs on the console?

@painor
Copy link
Member

painor commented Mar 9, 2021

strange. do you know what was the API call you made ? also did you change anything when creating the constructor ?
as for the logger you can import the Logger class and use Logger.setLevel("anything here"); to remove it. there are 4 levels
levels = ['error', 'warn', 'info', 'debug'];

@maheshbansod
Copy link
Author

The API call was users.GetFullUser
I made a smaller node js application to reproduce it:

const { TelegramClient } = require('telegram/dist')
const { StringSession } = require('telegram/dist/sessions');
const teletl = require('telegram/dist/tl');
const readline = require('readline');
const { Logger } = require('telegram/dist/extensions');

const apiId = process.env.API_ID // put your api id here [for example 123456789]
const apiHash = process.env.API_HASH // put your api hash here [for example '123456abcfghe']
const client = new TelegramClient(new StringSession(process.env.STRING_SESSION), apiId, apiHash, {
    connectionRetries: 3,
})

var username = 'justanotherlight';
client.start();
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});


Logger.setLevel("debug");

rl.question('make getfulluser? y for yes ', async (choice) => {

    if (choice != 'y') {
        return;
    }
    client.invoke(new teletl.Api.users.GetFullUser({ id: username }))
        .then((res) => console.log(res))
        .catch((err) => {
            console.log(err);
        });

    rl.close();
});

Apparently making multiple requests one after the other works if I do it in the above code, but if I wait and do nothing for like 30 seconds, it shows this

[2021-03-11T11:23:15.453Z] [INFO] - [connection closed]
{ Error: Invalid checksum (2699144061 when 2396756994 was expected). This packet should be skipped.
    at FullPacketCodec.<anonymous> (/home/null/apps/test-gramjs/node_modules/telegram/dist/network/connection/TCPFull.js:53:23)
    at Generator.next (<anonymous>)
    at fulfilled (/home/null/apps/test-gramjs/node_modules/telegram/dist/network/connection/TCPFull.js:5:58)
    at process._tickCallback (internal/process/next_tick.js:68:7) checksum: 2699144061, validChecksum: 2396756994 }

does it mean that I should do a client.start for every request if the requests are not that frequent(like a few minutes to a few hours)?

@painor
Copy link
Member

painor commented Mar 11, 2021

that's very weird. I tried your code and it's been running fine for 10 min. are you sure you're not using a VPN or have an IPV6 or something weird like that ?

@maheshbansod
Copy link
Author

Yea no it doesn't I think, one network I tried on had IPv6, but it had the same error as with the IPv4 one. Putting it on Heroku gives me the same thing too. So basically I see the same error message on different networks and different machines, so I can't make more than one request since the client is disconnected. Also, I don't use a VPN.
What should I be doing to fix this?
Is there any more information that I can provide to solve this problem?

@plukito
Copy link

plukito commented Mar 25, 2021

Also get this error. In my case I called messages.GetHistory

await telegram.invoke(new Api.messages.GetHistory({
    peer: new Api.InputPeerChat({
        chatId: parseInt(id)
    })
}));

@painor
Copy link
Member

painor commented Mar 25, 2021

well one thing for sure is that ipv6 is not supported.
As for getHistory try to pass the id directly instead of an InputPeerChat. It's very weird that this is happening.

@plukito
Copy link

plukito commented Mar 25, 2021

Yes, already tried that, but got the same error. Is there any recommendation?

@painor
Copy link
Member

painor commented Mar 25, 2021

which error are you getting btw the disconnect one ?

@plukito
Copy link

plukito commented Mar 25, 2021

same as the author, the Invalid checksum error

@plukito
Copy link

plukito commented Mar 30, 2021

I reinstalling everything and I haven't found any issue from checksum error.

All I did are removing yarn.lock and node_modules then ran yarn install

Thank you for your help @painor

@plukito
Copy link

plukito commented Mar 31, 2021

Sorry, seems the invalid checksum error is reapearring this morning. I suspect the network, but then I tried to run the same function in telethon and it ran successfully.

Does anyone have any idea why does this error reoccurring despite having no code changes?

@painor
Copy link
Member

painor commented Apr 10, 2021

I think the issue was in the TCP connection reader on slower connections. It might have been fixed in latest patch. you could also use connection:ConnectionTCPObfuscated in the args to try if it's better.
const client = new TelegramClient(new StringSession(stringSession), apiId, apiHash, { connection:ConnectionTCPObfuscated })

@maheshbansod
Copy link
Author

Yes, looks like it's fixed now. Thanks!

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

3 participants