question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Abort DB operations / Transaction using AbortSignal

See original GitHub issue

Feature Description

The Problem

Aborting DB operations is useful when the user abort some request when the DB operation is no longer needed (e.g. getting result for autocomplete and then the user type more characters (this is not my use case but rather a common use case that need the abort feature))

The Solution

Using AbortSignal to abort DB operation and transaction.

There are 2 approaches I have in mind:

  1. Passing signal
  2. Returning object with abort function

I prefer the 1st option as it keep the library usage design

Usage

When I use signal in the below example I mean an AbortSignal instance

Repository and EntityManager
userRepository.find({
    withDeleted: true,
    signal,
});
QueryBuilder
const firstUser = await connection
    .getRepository(User)
    .createQueryBuilder("user")
    .where("user.id = :id", { id: 1 })
    // here:
    .addSignal(signal)
    .getOne();
Transactions

Using Connection or EntityManager:


// An isolation level can be passed in the object near the signal property
await getManager().transaction({ signal }, async transactionalEntityManager => {

});

Using QueryRunner:

await queryRunner.startTransaction({ signal });

Using decorators: How this should be used? Maybe can set the abort signal on the passed manager

Passing the signal to the DB transaction will abort the transaction when the signal abort emit, passing

Considered Alternatives

Additional Context

Relevant Database Driver(s)

All of them basically

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
TheJaredWilcurtcommented, Feb 23, 2022

Node 12’s Maintenance support ends on 2022-04-30 (66 days from now).

Work on this feature could begin now and wait to be merged until after Node 12’s EOL, since it is relatively near.

0reactions
thebergamocommented, Aug 29, 2022

Every place that I see there isn’t any fluent interface around AbortSignal it’s mostly simply passing signal as part of the options of a given function that execute operations.

Is still any plan to support this feature?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I abort DB operation / transaction in TypeORM using ...
It looks like there is no such feature, I opened an issue ( TypeORM#8552 ) in GitHub requesting this feature.
Read more >
AbortSignal - Web APIs - MDN Web Docs - Mozilla
The AbortSignal interface represents a signal object that allows you to communicate ... Aborting a fetch operation using an explicit signal.
Read more >
Aborting a Transaction
To perform database activities under the control of a new transaction, you must obtain a fresh transactional handle. To abort a transaction, call...
Read more >
Using AbortController to deal with race conditions in React
This article explains what they are and provides a solution using the AbortController. Identifying a race condition. A “race condition” is when ...
Read more >
How to cancel an HTTP request in Node.js? - Atatus
Asynchronous processes allow faster compilation of requests, but many a time, they fall short of the time required to do so. In such ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found