mgcrea / prisma-queue

Minimalist postgresql job queue for Prisma
MIT License
53 stars 5 forks source link

Memory leak in 1.8.1 #2

Closed mckernanin closed 5 months ago

mckernanin commented 5 months ago

On upgrading my application from 1.7 to 1.8.1, my container memory usage went from ~200mb average to constantly running out of memory at my memory limit of 750mb. pgbouncer was also over 50%+ CPU usage. Upon downgrading to 1.7.0 (and leaving all other packages the same) the issue went away (memory usage back in check, postgres cpu averaging 1% across 2 cores.

RAM Usage: image

CPU Usage: image

mgcrea commented 5 months ago

Thanks for reporting this, my guess is that this is caused by this change:

https://github.com/mgcrea/prisma-queue/commit/a12dcfa2b394edcfca560ad60659855f28118b39#diff-9a9411d8c98c21f5ba0cbd900476870eea9c239077f02689846946b88077c423R217

Do you use the default concurrency of 1, do you have many processes?

Anything strange in the logs when using the env DEBUG=prisma-queue?

mckernanin commented 5 months ago

I'm using a concurrency of 2, the container in question is only running the queue processing. I'll do some testing when I have time and try to narrow down the issue in my local environment.

mgcrea commented 5 months ago

@mckernanin I have reverted the change and released a new 1.9.0 release without it, looking at the code again, it is pretty obvious that it will lead to memory leaks as you end up with X poll() function that have never ending while loops.

Will see if I can come up with something a bit more sound 😅

Thanks again!