denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.91k stars 5.39k forks source link

AbortSignals from Deno fetch do not work #26924

Open bdashore3 opened 3 hours ago

bdashore3 commented 3 hours ago

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 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)
bartlomieju commented 2 hours ago

@bdashore3 are you sure you are on 2.0.6? It works fine for me and this was fixed in https://github.com/denoland/deno/pull/26781

bdashore3 commented 2 hours ago

Hi @bartlomieju!

Yes, I'm on Deno v2.0.6. Here's my console info. Should've mentioned that I'm on Windows. Also, that example does not work on my system.

deno 2.0.6 (stable, release, x86_64-pc-windows-msvc)
v8 12.9.202.13-rusty
typescript 5.6.2
bdashore3 commented 2 hours ago

However, this does work on the macOS version of Deno. I cannot test Linux, but it should be working there as well if it works on Mac. So, this is a Windows specific issue that maybe fell through testing?

deno 2.0.6 (stable, release, aarch64-apple-darwin)
v8 12.9.202.13-rusty
typescript 5.6.2