Skip to content

[BUG] Durable Objects alarm not firing due to stale past alarms remaining in storage #929

@horai93

Description

@horai93

Describe the bug

When a Durable Objects alarm fails to fire (e.g., missing CACHE_PURGE_ZONE_ID/CACHE_PURGE_API_TOKEN, error in alarm handler, infrastructure issue), the past alarm timestamp remains in storage indefinitely. This causes subsequent purgeCacheByTags() calls to skip setting a new alarm, resulting in cache purge operations silently failing.

The current implementation doesn't check if an alarm is in the past:

const nextAlarm = await this.ctx.storage.getAlarm();
if (!nextAlarm) {
// Set an alarm to trigger the cache purge
this.ctx.storage.setAlarm(Date.now() + this.bufferTimeInSeconds * 1000);
}

If nextAlarm is a past timestamp, no new alarm is set, creating a deadlock where alarm() never fires and tags accumulate in the database.

Steps to reproduce

  1. Cause alarm to fail for any reason (e.g., error in alarm() method, possibly missing CACHE_PURGE_ZONE_ID/CACHE_PURGE_API_TOKEN)
  2. Call revalidateTag() which triggers purgeCacheByTags() - alarm is set
  3. Wait for alarm to fail
  4. Call revalidateTag() again - getAlarm() returns past timestamp, no new alarm is set
  5. alarm() is never called

Expected behavior

When revalidateTag() is called after a previous alarm has failed:

  • The stale past alarm should be detected and cleared
  • A new alarm should be set for the future

@opennextjs/cloudflare version

1.9.1

Wrangler version

4.40.2

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T8132
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.13.1
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 9.14.2
Relevant Packages:
  next: 15.5.4 // Latest available version is detected (15.5.4).
  eslint-config-next: 15.5.4
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.6.3
Next.js Config:
  output: standalone

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions