telegraf / telegraf-session-redis

Redis session middleware for Telegraf
MIT License
50 stars 25 forks source link

JavaScript heap out of memory #20

Closed Raingerlina closed 5 years ago

Raingerlina commented 5 years ago

Lately, the bot based on telegraf has started to use huge amounts of ram (peak was at 1Gb when normally it should vary from 80Mb to 150Mb) and I understand that the reason is that I use enormous session (normally I use 1 global session between all chats which contains all needed information).

Security context: 0x1f2df3318fe1 <JSObject>
    0: builtin exit frame: parse(this=0x1f2df3329c41 <Object map = 0x37b326d8f251>,0x2f766a05dfd1 <Very long string[27250046]>)

    1: callback [/var/bot/node_modules/telegraf-session-redis/lib/session.js:23] [bytecode=0x3b2101bde799 offset=32](this=0x3eb147effc09 <Command map = 0x12a1c854a979>,err=0x1f2df3302211 <null>,json=0x2f766a05dfd1 <Very long string[27250046]>)
    2: normal_reply(aka n...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x55abce2e5011 [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [node]
 7: 0x55abcdc98159 [node]
 8: 0x212decf196dd
Aborted (core dumped)

Is there any way to fix it?

dotcypress commented 5 years ago

@Raingerlina could you provide code example to reproduce this?

Raingerlina commented 5 years ago

@dotcypress

I guess it would be a problem to recreate the exact situation because it appears randomly during work. However, I sent the file with the part of the code to your e-mail hello@vitaly.codes (it is more comfortable for me to share it with just you).

Schematically conditions in which this error might appear:

  1. I store an array of objects in session across all chats. Right now it has about 18k objects in itself.
  2. By demand (executing a command in particular supergroup) any user in chat can get object printed in the chat and can redact it through the scene.
  3. Multiple users may ask for different objects and redact them simultaneously in 1 supergroup
  4. Bot understands with which object it should work via ids which are passed through callbacks (users presses buttons in the inline menu)
  5. In the same supergroup, any user may add object at any time by adding special hashtag to the message and sending it in the supergroup
Raingerlina commented 5 years ago

Reinstalled bot, split session into several subsessions: works just fine.