-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Memory Leak Triggered by "Server replied with a wrong session ID" #4213
Comments
Are you able to narrow down what is leaking? I can't think how this catch could lead to memory leaks: Telethon/telethon/network/mtprotosender.py Line 536 in 6a36066
All it's doing is retrying. You can also try with multiple processes. Perhaps |
What puzzles me the most is that when I only log in with 5 accounts (each of these accounts has about dozens of groups, and there are a large number of messages in the groups at any time), everything is normal. However, when I log in with around 8-10 accounts, abnormalities begin. The memory starts to rise at a rate of several megabytes per second. I also receive the error "Server replied with a wrong session ID". I'm uncertain whether the memory leak caused the "Server replied with a wrong session ID" error, or if this error led to the memory leak. I used objgraph to track the increase in objects in memory. When there are only 5 accounts, i.e., everything is normal, the data looks like this:
However, when I re-log in with around 10 accounts, the data starts to skyrocket:
Through testing, I limited the number of accounts logged in concurrently using semaphore, but it was of no use. Whether or not they are logged in concurrently, as soon as the total number of logged-in accounts reaches a certain amount, abnormalities will start to appear and memory will leak. Even if the accounts logged in earlier have executed "await client.disconnect()", and the accounts logged in later start to log in, the problem still occurs. I have tested all the methods I can think of, but I still haven't found the problem. I finally believe it might be due to Telethon. When multiple accounts with a large number of messages are logged in, I don't know what processing Telethon has done to cause this problem. |
Additionally, as shown in the code I provided earlier, after my accounts log in, they don't perform any operations and just enter an infinite delay loop. I wonder if Telethon can avoid processing any group messages on the logged-in accounts. Perhaps this could prevent the issues I'm encountering. |
My problem is the same as yours, have you solved it? |
Mine is the same, has it been resolved? |
Code that causes the issue
Expected behavior
This is the reduced group messaging code that can run multiple accounts in parallel to execute the message-sending task. It used to run smoothly without any issues.
Actual behavior
Recently, a severe problem emerged. If an account has too many groups or too many messages, when logging in with about 10 such accounts simultaneously, the error 'Server replied with a wrong session ID' occurs. Along with this, memory leakage happens continuously until all the memory is filled up. I initially thought it was a problem with my code. However, even after I removed all operations and only retained the client creation and infinite delay loop, the problem persisted. After a few rounds of the loop, the 'Server replied with a wrong session ID' error would still pop up, leading to a memory leak. Through tests, I found out that when logging in with more new accounts in parallel (these accounts don't have many messages), the problem doesn't occur. I'm unsure why this issue happens and how to resolve it.
Traceback
No response
Telethon version
1.30.3
Python version
3.10
Operating system (including distribution name and version)
windows 10
Other details
No response
Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.The text was updated successfully, but these errors were encountered: