#Pr4xy(Timothée CLEAR)-webhook timeout

1 messages · Page 1 of 1 (latest)

feral blaze
#

👋 happy to help

rare glacier
#

thank you for your reply

feral blaze
#

could you please share more details of what you're trying to accomplish and maybe share the code you're using. if you have a request id that would also be really helpful? here's how you can find one https://support.stripe.com/questions/finding-the-id-for-an-api-request

rare glacier
#

req_JgUKCiJykzNFTO

feral blaze
#

thx

rare glacier
feral blaze
#

Oh now I see your issue

rare glacier
#

nice

feral blaze
#

basically your webhook should reply as fast as possible with a Http 200

#

if you need to do more time-consuming tasks upon the reception of the webhook event you should probably want to do it asynchronously

#

it should be a fire and forget type of scenario from the webhook endpoint

rare glacier
#

So the process I did when I received the webhook event is too long?

feral blaze
#

yep most probably

rare glacier
#

ok I'm looking for that thanks

feral blaze
#

let me know if you need any more help

rare glacier
#

ok

#

I just checked, the code I am using is very similar to another payment method that works perfectly, I would be surprised if my function is longer than it

#

there is another possibility ?

feral blaze
#

I'm not sure

#

Pr4xy(Timothée CLEAR)-webhook timeout

rare glacier
#

The feature works well, even after the error, it just causes a delay which is annoying.

feral blaze
#

is there a pattern for getting this error? can you reproduce it?

rare glacier
#

yes

#

Each time I use this functionality

#

it concerns checkout.session.completed

feral blaze
#

could you please share your code for that particular switch case?

rare glacier
#

I can't send you my code, discord bloc it

feral blaze
#

why?

rare glacier
#

that is Clyde bot

feral blaze
#

try to use paste bin or something similar

rare glacier
feral blaze
#

is this getting executed in the webhooks endpoint?

rare glacier
#

yes

#

(the first code is the one that doesn't work the second is the function I was inspired by)

feral blaze
#

even if one of those two functions work, maybe because the query is faster or something, this is not good practice to wait for the execution of that function before responding back to Stripe with an HTTP 200

rare glacier
#
    protected function onPaymentSuccess($row, $transactionId)
    {
        $config              = OSMembershipHelper::getConfig();
        $row->transaction_id = $transactionId;
        $row->payment_date   = gmdate('Y-m-d H:i:s');
        $row->published      = 1;
        $row->store();
        if ($row->act == 'upgrade')
        {
            OSMembershipHelperSubscription::processUpgradeMembership($row);
        }
        elseif ($row->act == 'update')
        {
            OSMembershipHelperSubscriber::processUpdateMembership($row);
        }
        JPluginHelper::importPlugin('osmembership');
        JFactory::getApplication()->triggerEvent('onMembershipActive', array($row));
        OSMembershipHelper::sendEmails($row, $config);
    }```
#

this is where the function are call in the os_stripe.php

feral blaze
#

you should build your system in a way that handles tasks that you create from the webhook endpoint but don't wait for it to be executed

rare glacier
#

I don't understand, the site I'm working on is not mine, I just work after several people. I need to know that the payment was successful before using these functions.

#

I was just inspired by what was already on the site

#

The majority of the code provide from a Joomla's module

stiff mirage
#

Hi there 👋 jumping in as my teammate needed to step away. Please bear with me a moment while I get caught up on the context here.

rare glacier
#

Hello, thank you for your interest in my problem

stiff mirage
#

Apologies, but I'm struggling to grasp what the current question/concern is, would you mind summarizing for me?

rare glacier
#

I got a timeout error when I use the processUpdateMembership() function, the result is good but this error adds a delay to my request, so I'm trying to find out why it happens.

#

here is an exemple of this :

stiff mirage
#

Gotcha. We're not really going to have much insight into that. Since you're using the CLI to listen to events, that is essentially the webhook endpoint in this scenario which then immediately forwards events to your local server. So on our end it looks like the event was successfully received (because it was, by the CLI). So all of that processing and the resulting error is being handled locally and we don't have visibility into that. Is your server crashing or raising any errors when you see that timeout?

rare glacier
#

the server didn't crash but I got this error in a loop until the processing was finished

#

[Wed May 25 16:53:30.658858 2022] [php7:notice] [pid 9748:tid 1868] [client ::1:53814] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

stiff mirage
#

Looking back at your processUpdateMembership function, it looks like it's interacting with a database layer, which seems like a task that could easily overrun timeout limitations. This is a bit concerning because we will retry events that fail due to timeouts, so if you don't have some sort of logic to check if the event has already been processed then you'll attempt to process the information repeatedly. It seems to me like your server may have been busy handling the database operations.

What we ask be done instead, is that your server immediately responds to our requests. This response is not intended to track whether your business logic completed successfully, but is rather supposed to be used to confirm that your system received the event. So we recommend handling acknowledgement of receipt first, and then the heavier processing tasks either later or asynchronously.
https://stripe.com/docs/webhooks#acknowledge-events-immediately

rare glacier
#

Ok I think I understand the probleme

#

is there any danger in leaving my function like that? I have other things to develop and this code, despite the timeout, produces the expected result.

#

If I understand correctly, no, but I prefer to ask.

stiff mirage
#

My read on the situation is that your code will likely timeout when receiving an event for the first time, but may return a successful response on the second or third attempt. This isn't ideal, but should be alright as long as you have a way to make sure you're not fully processing the event each time.

The big thing you'll want to avoid is a scenario where our requests always time out, this will result in us flagging the endpoint as problematic and trying to disable it.

rare glacier
#

Okay, I got it. Thank you very much for your intervention.

#

I'm done with this topic

stiff mirage
#

Any time, happy to help!

rare glacier
#

So for my future interaction with this discord server, should I talk here or in the dev-help channel?

stiff mirage
#

We archive threads once the conversation for them comes to an end. If you have a follow-up question you can ask to have the thread re-opened if it was somewhat recent. For new questions you can raise those in #dev-help and we'll start a new thread for them.

rare glacier
#

ok have a nice day

stiff mirage
#

Thanks, hope you do the same. 👋