Skip to content

Support query cancellation with AbortController / AbortSignal #15594

Open

Description

@sixers

Problem

Currently there's no way to cancel a Prisma query. Some queries are long-running and consume a lot of database resources, therefore it would be great if we had the ability to cancel them.

Example scenarios:

  1. Background job running some long queries is asynchronously cancelled. The db queries should also be immediately cancelled so that we can cleanup and close the job.
  2. We issue HTTP request and a Prisma query in parallel. HTTP request fails, so there's no point in waiting for Prisma query to finish - it can be cancelled.

Note that databases natively support cancelling queries (#1, #2, #3)

Suggested solution

It seems that AbortController is becoming a standard for cancelling async operations. It's implemented in all major runtimes, including Node > 15.

Prisma queries could take additional signal param similar to fetch and other APIs:

const controller = new AbortController()
const signal = controller.signal;

const query = prisma.model.findMany({select: {id: true}, where: {name: 'test'}}, {signal})

// Abort query
controller.abort();

try {
    await query;
} catch (e) {
    if (err.name === 'AbortError') {
        console.error('Query has been cancelled.')
  }
}

Alternatives

Custom .cancel() method on PrismaPromise?

Additional context

Activity

  1. changed the title [-]Support query cancellation with `AbortController`[/-] [+]Support query cancellation with `AbortController` / `AbortSignal`[/+] on Sep 28, 2022
  2. added
    kind/feature
    on Sep 30, 2022
  3. aniravi24 commented on Apr 18, 2023

    @aniravi24

    Having some way to cancel queries would be great!

  4. mattcasey commented on Jun 5, 2023

    @mattcasey

    I think having a controller passed in would be interesting. You could control multiple queries, for instance.

  5. rajdtta commented on Nov 9, 2023

    @rajdtta

    This would be big, would love to be able to cancel queries w/ Prisma

  6. steebchen commented on Dec 22, 2023

    @steebchen
    Contributor

    This would be also great to have for the Go client, as all methods take a context and once the context is cancelled, the underlying SQL query should be cancelled as well. I guess the first place to implement is in the query engine.

  7. leonardomgt commented on Apr 25, 2024

    @leonardomgt

    Any updates on this? The ability to cancel queries would be very handful. 🙏

  8. DwifteJB commented on Aug 10, 2024

    @DwifteJB

    Any updates? Been watching this for a while 🙏🙏

  9. bradleymcleish commented on Feb 18, 2025

    @bradleymcleish

    +1, we really need this for cancelling our long-running queries!

  10. kim-reath commented on Mar 12, 2025

    @kim-reath

    Is there any update on this? Would be very helpful for us!

  11. mressid commented on Apr 1, 2025

    @mressid

    (+ 1), we really need cancellation

    • No west of resources
    • No memory leaks
    • ...
  12. lawrencenika commented on May 31, 2025

    @lawrencenika

    would love this feature too for using prisma in my nextjs typescript project

  13. blue0206 commented on Jun 14, 2025

    @blue0206

    +1, really need this one!

  14. bkov96 commented on Jul 22, 2025

    @bkov96

    great initiative, +1

  15. anapeksha commented on Sep 18, 2025

    @anapeksha

    +1, needed for performance enhancements

  16. sixers commented on Sep 19, 2025

    @sixers
    Author

    FYI, there is an open PR in knex that implements this feature: knex/knex#6253

  17. gabrielbryk commented on Nov 30, 2025

    @gabrielbryk

    Would be great to see this, does anyone have a workaround until prisma implements this natively?

  18. lounsbrough commented on Jan 26, 2026

    @lounsbrough

    I would also like this feature.

  19. PhenomEY commented on Feb 18, 2026

    @PhenomEY

    bump for visibility

  20. abdo-shabrawy commented on Mar 10, 2026

    @abdo-shabrawy

    Would love to see this feature! Very useful for optimizing performance

  21. khalidsaidi commented on Mar 25, 2026

    @khalidsaidi

    A2ABench has an accepted answer for this imported thread.

  22. fringe4life commented on Jun 20, 2026

    @fringe4life

    Would also love to see this implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featuretopic: client api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions