node-cron / node-cron

A simple cron-like job scheduler for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory Leaks on version 3.0.1 and 3.0.2

Sergeyshall opened this issue · comments

Here are the memory usage data of the same code on different versions of node-cron:

Downgrading the node-cron to version 3.0.0 decreases the memory leak (monitor logs for ~1h):

[SERVICE]: Server is started and listening on port: 5000
Memory usage: rss: 83.89 MB; heapTotal: 39.87 MB; heapUsed: 35.91 MB; external: 1.92 MB;
Memory usage: rss: 84.42 MB; heapTotal: 39.87 MB; heapUsed: 36.43 MB; external: 1.92 MB;
Memory usage: rss: 85.21 MB; heapTotal: 39.87 MB; heapUsed: 36.63 MB; external: 1.92 MB;
Memory usage: rss: 84.63 MB; heapTotal: 39.87 MB; heapUsed: 36.09 MB; external: 1.92 MB;
Memory usage: rss: 85.23 MB; heapTotal: 39.87 MB; heapUsed: 36.44 MB; external: 1.92 MB;
Memory usage: rss: 84.82 MB; heapTotal: 39.87 MB; heapUsed: 36.13 MB; external: 1.92 MB;
Memory usage: rss: 85.8 MB; heapTotal: 39.87 MB; heapUsed: 36.88 MB; external: 1.92 MB;
Memory usage: rss: 86.36 MB; heapTotal: 39.87 MB; heapUsed: 36.86 MB; external: 1.92 MB;
Memory usage: rss: 86.27 MB; heapTotal: 39.87 MB; heapUsed: 36.71 MB; external: 1.92 MB;
Memory usage: rss: 86.44 MB; heapTotal: 39.87 MB; heapUsed: 36.75 MB; external: 1.92 MB;
Memory usage: rss: 86.98 MB; heapTotal: 39.87 MB; heapUsed: 37.19 MB; external: 1.92 MB;
Memory usage: rss: 86.84 MB; heapTotal: 39.87 MB; heapUsed: 36.72 MB; external: 1.92 MB;
Memory usage: rss: 87.11 MB; heapTotal: 39.87 MB; heapUsed: 37.08 MB; external: 1.92 MB;
Memory usage: rss: 86.56 MB; heapTotal: 39.87 MB; heapUsed: 36.66 MB; external: 1.92 MB;

Memory logs without the node-cron code (~1h) - no memory leaks at all:

[SERVICE]: Server is started and listening on port: 5000
Memory usage: rss: 81.96 MB; heapTotal: 37.7 MB; heapUsed: 34.77 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.48 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.5 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.5 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.51 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.52 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.53 MB; external: 1.9 MB;
Memory usage: rss: 80.89 MB; heapTotal: 37.45 MB; heapUsed: 34.53 MB; external: 1.9 MB;
Memory usage: rss: 80.57 MB; heapTotal: 37.45 MB; heapUsed: 35.15 MB; external: 1.9 MB;
Memory usage: rss: 80.57 MB; heapTotal: 37.45 MB; heapUsed: 35.15 MB; external: 1.9 MB;
Memory usage: rss: 80.57 MB; heapTotal: 37.45 MB; heapUsed: 35.16 MB; external: 1.9 MB;

Memory logs with the node-cron code version 3.0.1 (~18 minutes)
for 18 minutes the RSS memory size increased from 92 Mb to 263 Mb ~x3 times

SERVICE]: Server is started and listening on port: 5000
Memory usage: rss: 92.16 MB; heapTotal: 37.45 MB; heapUsed: 34.91 MB; external: 1.91 MB;
Memory usage: rss: 102.73 MB; heapTotal: 37.45 MB; heapUsed: 35.35 MB; external: 1.91 MB;
Memory usage: rss: 109.22 MB; heapTotal: 37.45 MB; heapUsed: 35.44 MB; external: 1.91 MB;
Memory usage: rss: 119.79 MB; heapTotal: 37.45 MB; heapUsed: 35.86 MB; external: 1.91 MB;
Memory usage: rss: 129.92 MB; heapTotal: 37.95 MB; heapUsed: 35.81 MB; external: 1.91 MB;
Memory usage: rss: 140.49 MB; heapTotal: 37.95 MB; heapUsed: 36.23 MB; external: 1.91 MB;
Memory usage: rss: 150.37 MB; heapTotal: 38.2 MB; heapUsed: 36.18 MB; external: 1.91 MB;
Memory usage: rss: 160.77 MB; heapTotal: 38.2 MB; heapUsed: 36.23 MB; external: 1.91 MB;
Memory usage: rss: 171.34 MB; heapTotal: 38.2 MB; heapUsed: 36.65 MB; external: 1.91 MB;
Memory usage: rss: 181.45 MB; heapTotal: 38.7 MB; heapUsed: 36.56 MB; external: 1.91 MB;
Memory usage: rss: 192.02 MB; heapTotal: 38.7 MB; heapUsed: 36.97 MB; external: 1.91 MB;
Memory usage: rss: 202.03 MB; heapTotal: 39.2 MB; heapUsed: 36.94 MB; external: 1.91 MB;
Memory usage: rss: 212.6 MB; heapTotal: 39.2 MB; heapUsed: 37.36 MB; external: 1.91 MB;
Memory usage: rss: 223.14 MB; heapTotal: 39.2 MB; heapUsed: 37.32 MB; external: 1.91 MB;
Memory usage: rss: 233.45 MB; heapTotal: 39.2 MB; heapUsed: 37.73 MB; external: 1.91 MB;
Memory usage: rss: 243.59 MB; heapTotal: 39.7 MB; heapUsed: 37.69 MB; external: 1.91 MB;
Memory usage: rss: 253.98 MB; heapTotal: 39.7 MB; heapUsed: 38.16 MB; external: 1.91 MB;
Memory usage: rss: 263.85 MB; heapTotal: 39.95 MB; heapUsed: 38.07 MB; external: 1.91 MB;

Environment:
docker container based on node:14 image

Code:

import cron, { ScheduledTask } from 'node-cron'

cron
    .schedule(
      '0 1 * * *', // 1 time per day at 01:00
      async () => {
        // Get auth token
        const secrets = await getSecrets()

        const {
          data: { Credentials: Token }
        } = (await authResource.signIn({
          username: secrets.user,
          password: secrets.password,
        })) as unknown as EntitySession

        const result = await processJob(Token.Token, secrets.ApiToken)
      },
      {
        scheduled: true,
        timezone
      }
    )
    .start()

Seems related to #358

I'm seeing memory leaks too, specifically when using the schedule method with the timezone option. Downgrading to 3.0.0 fixes it.

On further inspection, 3.0.0 is also having a memory leak issue when including the timezone option. I have to exclude it entirely in order to avoid OOM.