mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
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:
parent
c58e83c9d7
commit
8051015bb8
@ -519,6 +519,15 @@ module.exports = class MemberRepository {
|
|||||||
if (!this._stripeAPIService.configured) {
|
if (!this._stripeAPIService.configured) {
|
||||||
throw new errors.BadRequestError(tpl(messages.noStripeConnection, {action: 'link Stripe Subscription'}));
|
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({
|
const member = await this._Member.findOne({
|
||||||
id: data.id
|
id: data.id
|
||||||
}, options);
|
}, options);
|
||||||
|
Loading…
Reference in New Issue
Block a user