dherault / dherault/serverless-offline

Computer freezes after wake up with scheduled events

Open
#1,530 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## 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

```yaml
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**

- `serverless` version: v3.21.0
- `serverless-offline` version: v8.8.81
- `node.js` version: v16.15.0
- `OS`: Windows 10

**Possible Solution**

Add these line here https://github.com/dherault/serverless-offline/blob/e907f894087db77f7aa86b40a40679a99c5c1965/src/events/schedule/Schedule.js#L47

```javascript
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

Contributor guide

Open the contributing guide

Research direction

Read src/events/schedule/Schedule.js at the linked scheduleJob entry point and compare it with the serverless.yml schedule example; focus on how late fire dates are handled. Done means overdue scheduled events are skipped and the maximum delay is configurable, including per-function configuration if that remains in scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.