serverless-offline
serverless-offline copied to clipboard
Computer freezes after wake up with scheduled events
Bug Report
Current Behavior
When the computer wakes up from a long standby, scheduled event are all fired at the same time executing a lot of lambdas, the computer freezes.
Sample Code
- file: serverless.yml
service: my-service
plugins:
- serverless-offline
provider:
runtime: nodejs16.x
stage: dev
functions:
myLambda:
handler: src/lambdas/myLambda.handler
events:
- schedule: rate(1 minutes)
- file: handler.js
Not relevant
Expected behavior/code
Events triggered too late should not be fired (or at least it should be configurable, ideally per function with a "too late" time limit)
Environment
serverlessversion: v3.21.0serverless-offlineversion: v8.8.81node.jsversion: v16.15.0OS: Windows 10
Possible Solution
Add these line here https://github.com/dherault/serverless-offline/blob/e907f894087db77f7aa86b40a40679a99c5c1965/src/events/schedule/Schedule.js#L47
nodeSchedule.scheduleJob(cron, async (fireDate) => {
const delay = Date.now() - fireDate.valueOf();
if (delay > 5 * 60 * 1000) {
log.error(
`Scheduled function fired too late: [${functionKey}] ${delay}ms late`,
)
return;
}
5 * 60 * 1000 should be replace by a configurable max delay
Additional context/Screenshots
None
thank you for filing the issue @jer-sen
haven't tried to repro it yet, but would you mind putting up a PR with the suggested fix, possibly with some comments (I assume it's probably not easy to write a test)?
@dnalborczyk sorry I realy don't have time for that. Also the best would be to make it configurable but it would take me a lot of time to dig into documentation and configuration system. The fix works well on my project. For the test, maybe you can extract scheduleJob callback and call it with new Date(Date.now() - 24 * 60 * 60 * 1000)) and new Date() to check that there is an error only in the first case.
sorry I realy don't have time for that
that's understandable, no problem. it just might take a while that someone will get to it, that's all.