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

Referenced message entries exceed the max messages settings #904

Closed
2 tasks done
norinorin opened this issue Nov 12, 2021 · 1 comment · Fixed by #1192
Closed
2 tasks done

Referenced message entries exceed the max messages settings #904

norinorin opened this issue Nov 12, 2021 · 1 comment · Fixed by #1192
Labels
bug Something isn't working priority This should be worked on before anything else

Comments

@norinorin
Copy link
Contributor

norinorin commented Nov 12, 2021

Steps to reproduce

There's no steps but to run the bot as usual. Send a message, let's say it's message A. Then, reply to message A, this reply is message B. And finally, reply to message B.

Expected result

Cache.get_messages_view() returns a bit more than n messages if not exact, where n is the max messages we put in the config. Message B has the referenced_message attribute set to A.

Actual result

It returns a lot more messages than it should. Turned out, Cache._referenced_messages seems to be caching messages that should've been GC'd as they're no longer referenced. Message B has the referenced_message attribute set to None. This would lead to a memory leak if people were to reply a lot as it would leave some referenced messages untouched when garbage collecting.

System info

hikari (2.0.0.dev104) [HEAD]
located at /home/nori/.local/lib/python3.9/site-packages/hikari
CPython 3.9.7 GCC 11.1.0
Linux arch 5.14.16-zen1-1-zen #1 ZEN SMP PREEMPT Tue, 02 Nov 2021 22:23:00 +0000 x86_64

Further info

Might be somewhat relevant to #877 and perhaps #894 if we were to hide referenced messages?

Checklist

  • I have made sure to remove ANY sensitive information (bot token, passwords, credentials, personal details, etc.).
  • I have searched the issue tracker and have made sure it's not a duplicate. If it is a follow up of another issue, I have specified it.
@norinorin norinorin added the bug Something isn't working label Nov 12, 2021
@norinorin
Copy link
Contributor Author

Alright, so the problem was that Discord doesn't send second-level referenced_message. Meaning if we have B references to A and C references to B, B's referenced message will be None as opposed to A, thus leaving A's ref count to remain the same when garbage collecting. And since Discord provides you with the ID of the referenced message, this is what I do to get around currently https://github.com/norinorin/nokari/blob/31fd0078af81269204dd3370e932840c916cb03a/nokari/core/cache.py#L154-L162. I could make a PR if you'd like me to.

Jump link to relevant messages: https://discord.com/channels/574921006817476608/700378161526997003/910704551131246663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority This should be worked on before anything else
Projects
None yet
2 participants