#dannnnnnnnnnnnnnnnnnnnnn_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1387390440994504795
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi there!
The request ID in question req_w5LjIcpVFwQCNN however it was from the end of May so I can't seem to see it in Stripe to figure out if it is a rate-limited request or a lock timeout
you are using the stripe-python SDK?
yeah using the stripe-python sdk
looks like max_network_retries is already set to 2 by default: https://github.com/stripe/stripe-python/blob/a90ce5b34c55561fe4c4de34b3b48ec8b7a3e6a1/stripe/__init__.py#L44
Yeah which I think still wasn't enough as the transfer that we were trying to create never got created in Stripe.
do you think it's best to increase that number? would it ever cause any harm in doing so?
oh wait thats hard coded to 2 isn't it - ignore this, I see we can just set it with stripe.max_network_retries
oh wait thats hard coded to 2 isn't it - ignore this, I see we can just set it with stripe.max_network_retries
it's set to 2 by default, but you can change that value as shown here: https://github.com/stripe/stripe-python?tab=readme-ov-file#configuring-automatic-retries
do you think the correct solution here is to increase this value? is there ever any way that this could cause things we won't expect to happen?
increasing max_network_retries could negatively impact your rate limits.
if we set it to 2 by default, it means its the value we recommend for most integrations.
So with regards to the inital RateLimitError msg we received is that most likely a result from a RateLimit rather than a lock-timeout as possibly suggested in the help doc? And does that mean the correct solution then is to implement some retry logic following this https://docs.stripe.com/rate-limits?locale=en-GB#handling-limiting-gracefully help doc?
and also about it could negatively impact our rate limits, does the max_network_retries not have a drop off like retry after 1 second then 2 then 10 etc?
Hi ๐
I'm stepping in as my colleague needs to go soon
So the problem is you are encountering object locks and looking to identify the best approach?
hey, yeah either it was a rate limit or object locking, I thought it was a rate limit but after reading your docs apparently it could be either and I can tell by looking at the request. However I can't tell as the request is too old so I don't think I can see it on Stripe. But yeah basically it seems like there are two options, increase that value to something higher than 2 and I was wondering that would fix these scenarios/have any downside or option 2 being that we implement our own retry logic for any 429 responses from Stripe
yeah that makes sense, what do you think is the better appraoch to our scenario then?
It depends on the timeouts you are hitting. It might be worth testing out but if the objects are locked for a significant amount of time, you might still get the same issue.
Do you occasionally get rate limit errors as well?
nah we have got them like once at the end of May once in March and then before that October 2024 so very rarely. How can we test if objects are locked for significant time?
I'm kinda leaning towards it was probably a RateLimit issue rather than an object locking issue just because it came from creating Transfer objects
Can you share one of the requests where you got a 429 response?
yeah its above in the chat, its req_w5LjIcpVFwQCNN
Yeah see that response IS a lock timeout. This means that some other process is in the process of mutating an object that is invovled in this request. It could possibly be the Account object you are trying to send this transfer to.
oh interesting, is there a way I can see the request through the dashboard cause I can't seem to view it
The request you just shared with me? Or the request that locked the object?
the request I shared, if I search for it in the search bar it doesn't seem to come up or am I looking in the wrong place for requests
but would also be interesting to know what locked the object too if you know that
https://dashboard.stripe.com/logs/req_w5LjIcpVFwQCNN
So you cant see this?
oh perfect yeah I can, just wasn't appearing when I use the search bar
so is there a way we can figure out what locked the object? is that possible to find out?
Not directly on your end and only after manual investigation on mine.
Ok, is that something I can request somehow or are you looking into it at the moment for me?
I can look it up this one time but it isn't something you can repeatedly request
Ok perfect thank you so much
Okay it looks like the account was locked as part of a automatic update being applied. It should've unlocked in less than 1s. Essentially this request just got unlucky.
sorry for the late reply was on a quick call. So because we've had this occur a few times, is there a good way to prevent this from happening on our end? Like should implement some retry logic then for any 429 responses for scenarios like these?
and the automatic update is that something that we started or is that something that Stripe just does occasionally?
This was something internal, as far as I can tell.
And I think building your own retry logic would be a good idea, since the immediate retry that the SDK will use is likely to mean the initial request and first retry will both likely fail
Ok that sounds good, one last thing from me then. That said back to the whole max_network_retries, if that has a drop off could we not just increase that value to like a 5 or something and would that handle it? If not then yeah we'll implement some retry logic
It does have an exponential back-off and you can likely achieve what you want by increasing the number of retries but those will count towards your request rate limit.
So let's say that you have a request that returns a 429, the immeidate retry returns a 429, and the second retry succeeds
There's at least one request there you could do without
Of course that is only an issue if you are getting close to hitting rate limits
Ah ok I see what you're saying. We've never been rate limited so I imagine this would be fine though as in theory our retry logic would just be doing the same thing of wait 1 second try the request again, wait 2 seconds try again etc
And I guess my other question is if we implement our own retry logic should we be setting that max network retries to 0? That way our own retry system doesnโt interfere with the stripe sdks retry logic/increase our number of requests
Hi there ๐ jumping in as my teammate needed to step away. Yes, if you're implementing your own retry logic, I'd suggest disabling our automatic retries by setting that value to 0.
Ok and before I implement this retry logic, just to check does max network retries handle more logic that we might miss with our own logic? Like does it only handle 429 responses or is there more it does?
There's more to it than that. It also handles situations where no response is received, and it's unclear whether the request reached us and was successful. In those cases we make an idempotent request to safely retry the operation in a way where nothing happens if the previous request was successful.
It's our automatic implementation of the flow we discuss here:
https://docs.stripe.com/api/idempotent_requests
Ok that's all from me then. Thank you all for your help on the matter, it's much appreciated.