Skip to content

"Error: WARNING: Date in past. Will never be fired." crash inside callback wrapperΒ #813

@Cyberbeni

Description

@Cyberbeni

Description

I was using 2.2.0 but cross-checking the code with 3.1.6, this issue still exists.

I have a daily schedule to set up triggers for the day:
https://github.com/Cyberbeni/node-red-contrib-cb-suncron/blob/3b3441c95a0fb4ab2356e906c810d3ef0e8de80f/src/SuncronLocation.ts#L29-L34

Setting up the jobs looks like this: https://github.com/Cyberbeni/node-red-contrib-cb-suncron/blob/3b3441c95a0fb4ab2356e906c810d3ef0e8de80f/src/Suncron.ts#L44-L59

I had this Node-RED crash today at the time that the cron job should have fired (and probably had multiple similar ones in the past as I had some skipped schedules):

9 Dec 15:49:24 - [red] Uncaught Exception:
9 Dec 15:49:24 - [error] Error: WARNING: Date in past. Will never be fired.
    at CT.sendAt (/data/node_modules/cron/lib/time.js:177:12)
    at CT.getTimeout (/data/node_modules/cron/lib/time.js:202:29)
    at Timeout.callbackWrapper [as _onTimeout] (/data/node_modules/cron/lib/job.js:141:36)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

Expected Behavior

If diff is more than 0 but newTimeout would be negative (because slow hardware or whatever), we shouldn't throw an error that can't be handled.

Actual Behavior

Occasional crash with the included call stack.

Possible Fix

Treat this.cronTime.getTimeout() throwing an error as if diff was not more than 0.

Steps to Reproduce

Remove if (diff > 0) check and insert a 1 second sleep before this line to imitate slow hardware:

let newTimeout = this.cronTime.getTimeout();

Then just setup a job with a single Date and an onTick callback.

Context

see description

Your Environment

  • cron version: 2.2.0
  • NodeJS version: nodered/node-red:2c51c6aaed04 docker container
  • Operating System and version: nodered/node-red:2c51c6aaed04 docker container
  • TypeScript version (if applicable): 4.9.5
  • Link to your project (if applicable): https://github.com/Cyberbeni/node-red-contrib-cb-suncron

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededstatus:waiting-on-responseWaiting on a response/more information from the user

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions