Durable Objects - Prevent Durable Object alarm retries when using `ctx.abort()`
- Announced
- Tags
- Durable-Objects
- Severity
- info, set by
reef/rss-rule-v1 - Source
- https://developers.cloudflare.com/changelog/post/2026-08-25-durable-object-alarm-abort-no-retry/
<p>By default, an alarm interrupted by <code>ctx.abort()</code> retries after the Durable Object resets. Pass <code>{ retryAlarm: false }</code> when the alarm should stop instead:</p> <div><div data-nb-tabs data-nb-sync-key="workersExamples" class><div class="relative flex border-b border-border" role="tablist" data-nb-tabs-list><span class="bg-primary pointer-events-none absolute -bottom-px h-0.5 rounded-t-sm transition-[left,width] duration-200 ease-out" data-nb-tabs-indicator aria-hidden="true"></span></div><div class="mt-3"><div role="tabpanel" data-nb-tabs-content data-nb-tab-label="JavaScript" class><figure class="nb-code-figure nb-code-figure-titled" data-nb-lang="js"><figcaption class="nb-code-title"><span class="nb-code-title-name">src/index.js</span><span class="nb-code-title-lang">js</span></figcaption><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="js" data-nb-lang="js"><code><span class="line"><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> { DurableObject } </span><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-mdbnqw"> "cloudflare:workers"</span><span class="nb-shiki-140thh">;</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">export</span><span class="nb-shiki-1itgoe"> class</span><span class="nb-shiki-1t8gfj"> CleanupTask</span><span class="nb-shiki-1itgoe"> extends</span><span class="nb-shiki-1t8gfj"> DurableObject</span><span class="nb-shiki-140thh"> {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> async</span><span class="nb-shiki-1t8gfj"> alarm</span><span class="nb-shiki-140thh">() {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> await</span><span class="nb-shiki-dzsirb"> this</span><span class="nb-shiki-140thh">.ctx.storage.</span><span class="nb-shiki-1t8gfj">deleteAll</span><span class="nb-shiki-140thh">();</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-dzsirb"> this</span><span class="nb-shiki-140thh">.ctx.</span><span class="nb-shiki-1t8gfj">abort</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-mdbnqw">"Cleanup complete"</span><span class="nb-shiki-140thh">, { retryAlarm: </span><span class="nb-shiki-dzsirb">false</span><span class="nb-shiki-140thh"> });</span></span> <span class="line"><span class="nb-shiki-140thh"> }</span></span> <span class="line"><span class="nb-shiki-140thh">}</span></span></code></pre></figure></div><div role="tabpanel" data-nb-tabs-content data-nb-tab-label="TypeScript" class><figure class="nb-code-figure nb-code-figure-titled" data-nb-lang="ts"><figcaption class="nb-code-title"><span class="nb-code-title-name">src/index.ts</span><span class="nb-code-title-lang">ts</span></figcaption><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="ts" data-nb-lang="ts"><code><span class="line"><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> { DurableObject } </span><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-mdbnqw"> "cloudflare:workers"</span><span class="nb-shiki-140thh">;</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">export</span><span class="nb-shiki-1itgoe"> class</span><span class="nb-shiki-1t8gfj"> CleanupTask</span><span class="nb-shiki-1itgoe"> extends</span><span class="nb-shiki-1t8gfj"> DurableObject</span><span class="nb-shiki-140thh"> {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> async</span><span class="nb-shiki-1t8gfj"> alarm</span><span class="nb-shiki-140thh">()</span><span class="nb-shiki-1itgoe">:</span><span class="nb-shiki-1t8gfj"> Promise</span><span class="nb-shiki-140thh"><</span><span class="nb-shiki-dzsirb">void</span><span class="nb-shiki-140thh">> {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> await</span><span class="nb-shiki-dzsirb"> this</span><span class="nb-shiki-140thh">.ctx.storage.</span><span class="nb-shiki-1t8gfj">deleteAll</span><span class="nb-shiki-140thh">();</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-dzsirb"> this</span><span class="nb-shiki-140thh">.ctx.</span><span class="nb-shiki-1t8gfj">abort</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-mdbnqw">"Cleanup complete"</span><span class="nb-shiki-140thh">, { retryAlarm: </span><span class="nb-shiki-dzsirb">false</span><span class="nb-shiki-140thh"> });</span></span> <span class="line"><span class="nb-shiki-140thh"> }</span></span> <span class="line"><span class="nb-shiki-140thh">}</span></span></code></pre></figure></div></div></div><script type="module" src="https://developers.cloudflare.com/home/runner/work/cloudflare-docs/cloudflare-docs/src/components/ui/tabs/Tabs.astro?astro&type=script&index=0&lang.ts"></script></div> <p>For example, an alarm that deletes its storage can use this option to avoid repeating the cleanup or re-running the Durable Object constructor.</p> <p>Alarms can run concurrently with other requests to the same Durable Object. If another request calls <code>ctx.abort()</code> while an alarm is running, the <code>retryAlarm</code> option on that call also controls whether the alarm retries.</p> <p>The default retry prevents an unrelated request from permanently canceling the alarm. Set <code>retryAlarm: false</code> on every abort path that should stop an in-progress alarm, not only on calls from the alarm handler. Existing calls to <code>ctx.abort()</code> keep retrying alarms.</p> <p>For local development, <code>retryAlarm</code> requires Wrangler 4.126.0 or later.</p> <p>For more information, refer to <a href="https://developers.cloudflare.com/durable-objects/api/state/#abort"><code>ctx.abort()</code></a>.</p>
The text above is the source's. reef added the severity, the dates it could read from the text, and the endpoints and scopes named in code.