oja icon indicating copy to clipboard operation
oja copied to clipboard

Memory leak on long running scripts

Open buffcode opened this issue 6 years ago • 2 comments

Hi,

first of thanks for your library, it works quite well and encourages us to write small actions for our business logics, just as intended :)

We noticed, that the library has one inherent memory leak as the queue will never be cleaned. As we use the library in a NodeJS service which usually won't restart, the queue will continuously grow and eventually hit the memory limit.

We fixed this for the time being by shifting the first element from the queue after emitting. This works in our use case but of cause will cause problems in use cases where consumers are defined later (aka repub). As such it would be nice to have the option to decide, whether or not a value should be put into the queue.

Do you have any plans into this direction or any other suggestions on how to handle this scenario?

Thanks in advance! Laurens

buffcode avatar Sep 18 '18 17:09 buffcode

@buffcode did you figure out any better fix since asking this question?

OriginalYellow avatar Mar 15 '19 03:03 OriginalYellow

@buffcode @OriginalYellow The module has been created to be used in a single request context and never meant to be used in a long-running process. So, this is not a memory leak, but a feature to keep the queue of events. https://github.com/dimichgh/oja#pubsub-flow

I can add a TTL for any topic even to live, but still, it is not recommended to use it in ling running flow You may also want to look at newly added actions flow which makes it even more clear to stick this into request scope.

dimichgh avatar Oct 07 '19 22:10 dimichgh