Fixed race condition when linking subscriptions

no-issue

Without forcing linkSubscription to run inside a transaction - it's
possible to have race conditions where it is called twice, and attempt
to insert duplicate rows into the database.
This commit is contained in:
Fabien O'Carroll 2021-10-18 16:36:56 +02:00
parent c58e83c9d7
commit 8051015bb8

View File

@ -519,6 +519,15 @@ module.exports = class MemberRepository {
if (!this._stripeAPIService.configured) {
throw new errors.BadRequestError(tpl(messages.noStripeConnection, {action: 'link Stripe Subscription'}));
}
if (!options.transacting) {
return this._Member.transaction((transacting) => {
return this.linkSubscription(data, {
...options,
transacting
});
});
}
const member = await this._Member.findOne({
id: data.id
}, options);