From 543767d3889f5cf7d9ad1620f0c7b076598938a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Tue, 24 Dec 2024 08:49:43 +0100 Subject: [PATCH] server/discount: raise redemption lock timeout to handle slow Stripe requests --- server/polar/discount/service.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/polar/discount/service.py b/server/polar/discount/service.py index fce928082b..7176b6dd6b 100644 --- a/server/polar/discount/service.py +++ b/server/polar/discount/service.py @@ -395,8 +395,11 @@ async def is_redeemable_discount( async def redeem_discount( self, session: AsyncSession, locker: Locker, discount: Discount ) -> AsyncIterator[DiscountRedemption]: + # The timeout is purposely set to 10 seconds, a high value. + # We've seen in the past Stripe payment requests taking more than 5 seconds, + # causing the lock to expire while waiting for the payment to complete. async with locker.lock( - f"discount:{discount.id}", timeout=5, blocking_timeout=5 + f"discount:{discount.id}", timeout=10, blocking_timeout=10 ): if not await self.is_redeemable_discount(session, discount): raise DiscountNotRedeemableError(discount)