Skip to content

Api route req on close event not triggered when request is cancelled #52809

Closed
@jbojcic1

Description

@jbojcic1

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
    Binaries:
      Node: 18.14.2
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.10-canary.8
      eslint-config-next: 13.4.8
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/blissful-driscoll-y78mrd

To Reproduce

  1. open the link from above
  2. click on "Trigger API call" button
  3. click on "Cancel API call" button and note in browser network tab that the request which was previously pending is now cancelled
  4. note how req.on("close" event handler didn't run and API route work is still being done

Describe the Bug

Request close event is not firing in the API route when the caller cancels the request

Expected Behavior

Request close event should be fired so that any necessary cleanup can be done

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    RuntimeRelated to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions