Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactional not rollback excute Promise.all Propagation.REQUIRED #100

Open
x302502 opened this issue Jun 16, 2021 · 1 comment
Open

Transactional not rollback excute Promise.all Propagation.REQUIRED #100

x302502 opened this issue Jun 16, 2021 · 1 comment

Comments

@x302502
Copy link

x302502 commented Jun 16, 2021

I have a function that uses

@transactional()
excute() {
...
const promises = [];
promises.push(this.receiptDetailRepo.save(listReceiptDetail))
promises.push(this.lotattributeRepo.insert(listLotattribute))
promises.push(this.lotxlocxidRepo.save(listIvUpdate))
promises.push(this.lotxlocxidRepo.insert(listIvInsert))
promises.push(this.itrnRepo.insert(listItrn))
promises.push(Promise.reject("ERROR"));
const [resReceiptDetails] = await Promise.all(promises);
}

but it doesn't rollback;

What I am missing?

@svvac
Copy link
Contributor

svvac commented Aug 5, 2022

This is a common gotcha.

Promise.all() rejects as soon as the first promise gets rejected, triggering a rollback. If other operations referencing the transaction are still pending, they get orphaned and executed outside the transaction, making it appear as if the rollback did not happen.

You need to use something like Promise.allSettled() instead, and throw if any promise failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants