denoland/celldPublic

self-hosted, distributed Durable Objects

v0.4.1: cron `scheduled` handler: `waitUntil` work is not drained after the handler settles

SA

Running a [Nitro](https://nitro.build) (`cloudflare_module` preset) Worker on celld 0.4.1 with `triggers.crons: ["*/5 * * * *"]`. Nitro's `scheduled` handler does `context.waitUntil(runTasks())` and returns immediately, which is the documented Cloudflare pattern.

On celld the alarm fires every occurrence (`.cron:<script>` cell, `cell_console` shows my log line at :00.00x each time), but the task inside `waitUntil` never finishes: its first KV `put` never resolves, no error is logged, and the promise is left pending forever. Nitro dedupes a still-running task, so every later occurrence reuses that pending promise and the schedule effectively runs once.

Looking at the harness, [`CelldCronSchedule.alarm()`](https://github.com/denoland/celld/blob/v0.4.1/crates/celld/js/harness.js#L4934) calls [`__endEvent()` in its `finally`](https://github.com/denoland/celld/blob/v0.4.1/crates/celld/js/harness.js#L4975) and moves straight on to [`_arm()`](https://github.com/denoland/celld/blob/v0.4.1/crates/celld/js/harness.js#L4978), while the fetch path keeps the aggregate with [`drain = __endEvent()`](https://github.com/denoland/celld/blob/v0.4.1/crates/celld/js/harness.js#L4772) and [awaits it before replying](https://github.com/denoland/celld/blob/v0.4.1/crates/celld/js/harness.js#L4781). So I'd say the cron cell just doesn't drain the event's `waitUntil` aggregate before it re-arms and [`__fireAlarm`](https://github.com/denoland/celld/blob/v0.4.1/crates/celld/js/harness.js#L4884) ends the actor event.

Awaiting the work inside `scheduled` instead of handing it to `waitUntil` fixes it on my side (verified: tick lands at `:00.003` on the next occurrence), so this is only about `waitUntil` parity with Cloudflare. Happy to test a build if useful

  1. bartlomiejuassigned bartlomieju2 months ago on GitHub

  2. SA
    Author

    Just noticed #189, though that one shows `waitUntil` passing on the DO WebSocket path; this is the cron cell's alarm and `waitUntil` specifically, so they should be separate bugs

  3. BA

    Thanks for the report. I got fix incoming, should be included in the next release.

  4. bartlomiejuclosed2 months ago on GitHub