---
title: Handle incoming request cancellation in Workers with Request.signal
description: Workers can now add event listeners on Request.signal and perform tasks when the request is cancelled by the client
image: https://edgetunnel-b2h.pages.dev/changelog-preview.png
---

> Documentation Index  
> Fetch the complete documentation index at: https://edgetunnel-b2h.pages.dev/changelog/llms.txt  
> Use this file to discover all available pages before exploring further. 

[Skip to content](#%5Ftop) 

# Changelog

New updates and improvements at Cloudflare.

[ Subscribe to RSS ](https://edgetunnel-b2h.pages.dev/changelog/rss/index.xml) [ View RSS feeds ](https://edgetunnel-b2h.pages.dev/fundamentals/new-features/available-rss-feeds/) 

![hero image](https://edgetunnel-b2h.pages.dev/_astro/hero.CVYJHPAd_26AMqX.svg) 

[ ← Back to all posts ](https://edgetunnel-b2h.pages.dev/changelog/) 

## Handle incoming request cancellation in Workers with Request.signal

May 22, 2025 

[ Workers ](https://edgetunnel-b2h.pages.dev/workers/) 

In Cloudflare Workers, you can now attach an event listener to [Request](https://edgetunnel-b2h.pages.dev/workers/runtime-apis/request/) objects, using the [signal property ↗](https://developer.mozilla.org/en-US/docs/Web/API/Request/signal). This allows you to perform tasks when the request to your Worker is canceled by the client. To use this feature, you must set the [enable\_request\_signal](https://edgetunnel-b2h.pages.dev/workers/configuration/compatibility-flags/#enable-requestsignal-for-incoming-requests) compatibility flag.

You can use a listener to perform cleanup tasks or write to logs before your Worker's invocation ends. For example, if you run the Worker below, and then abort the request from the client, a log will be written:

* [  JavaScript ](#tab-panel-2911)
* [  TypeScript ](#tab-panel-2912)

**index.js**

```js
export default {
  async fetch(request, env, ctx) {
    // This sets up an event listener that will be called if the client disconnects from your
    // worker.
    request.signal.addEventListener("abort", () => {
      console.log("The request was aborted!");
    });


    const { readable, writable } = new IdentityTransformStream();
    sendPing(writable);
    return new Response(readable, {
      headers: { "Content-Type": "text/plain" },
    });
  },
};


async function sendPing(writable) {
  const writer = writable.getWriter();
  const enc = new TextEncoder();


  for (;;) {
    // Send 'ping' every second to keep the connection alive
    await writer.write(enc.encode("ping\r\n"));
    await scheduler.wait(1000);
  }
}
```

**index.ts**

```ts
export default {
  async fetch(request, env, ctx): Promise<Response> {
    // This sets up an event listener that will be called if the client disconnects from your
    // worker.
    request.signal.addEventListener('abort', () => {
      console.log('The request was aborted!');
    });


    const { readable, writable } = new IdentityTransformStream();
    sendPing(writable);
    return new Response(readable, { headers: { 'Content-Type': 'text/plain' } });
  },
} satisfies ExportedHandler<Env>;


async function sendPing(writable: WritableStream): Promise<void> {
  const writer = writable.getWriter();
  const enc = new TextEncoder();


  for (;;) {
    // Send 'ping' every second to keep the connection alive
    await writer.write(enc.encode('ping\r\n'));
    await scheduler.wait(1000);
  }
}
```

For more information see the [Request documentation](https://edgetunnel-b2h.pages.dev/workers/runtime-apis/request).

```json
{"@context":"https://schema.org","@type":"BlogPosting","@id":"https://edgetunnel-b2h.pages.dev/changelog/post/2025-05-22-handle-request-cancellation/#page","headline":"Handle incoming request cancellation in Workers with Request.signal · Changelog","description":"Workers can now add event listeners on Request.signal and perform tasks when the request is cancelled by the client","url":"https://edgetunnel-b2h.pages.dev/changelog/post/2025-05-22-handle-request-cancellation/","inLanguage":"en","image":"https://edgetunnel-b2h.pages.dev/changelog-preview.png","dateModified":"2025-05-22","datePublished":"2025-05-22","publisher":{"@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com/"},"isPartOf":{"@type":"WebSite","@id":"https://edgetunnel-b2h.pages.dev/#website","name":"Cloudflare Docs","url":"https://edgetunnel-b2h.pages.dev/"}}
```
