kingbri
kingbri2mo ago

AbortSignals not working in Deno

Hi there, I'm trying to create a Hono server with a disconnect handler. When I cancel the request from my client, the abort signal from the raw Request object never changes to true. This code works on both Hono and Bun, so I think this is an issue with Deno's fetch API. See example below (requires Hono)
import { Hono } from 'hono'

const app = new Hono()

async function stall(stallTime = 3000) {
await new Promise(resolve => setTimeout(resolve, stallTime));
}

app.get('/hello', async (c) => {

// Should show up when hitting Cancel in Postman
c.req.raw.signal.addEventListener("abort", () => {
console.log("Aborted");
})

// Simulate a long-running task
await stall(10000);
return c.text("Hello from Hono!");
})

Deno.serve(app.fetch)
import { Hono } from 'hono'

const app = new Hono()

async function stall(stallTime = 3000) {
await new Promise(resolve => setTimeout(resolve, stallTime));
}

app.get('/hello', async (c) => {

// Should show up when hitting Cancel in Postman
c.req.raw.signal.addEventListener("abort", () => {
console.log("Aborted");
})

// Simulate a long-running task
await stall(10000);
return c.text("Hello from Hono!");
})

Deno.serve(app.fetch)
1 Reply
kingbri
kingbriOP2mo ago
GitHub
AbortSignals from Deno fetch do not work on Windows · Issue #26924 ...
Version: Deno 2.0.6 Hi there, I'm trying to create a Hono server with a disconnect handler. When I cancel the request from my Postman client, the abort signal from the raw Request object never ...

Did you find this page helpful?