Vercel function seems to pause after a short time (<1s)

Hi, this is a very weird issue. I have a sveltekit site hosted on vercel. I have a stripe webhook endpoint. When the webhook gets hit, some of my code runs but execution pauses mid-way. Execution only continues when I make another request to vercel (like reloading the page) and that runs some more part of the code after which it pauses again. I have to make several requests for the entire function to finish executing.

For example, if the initial webhook gets run at 12:30, it will only run a part of the function. Then when I make another 3-4 requests at 1:00, only then will the function finish executing. Each of those requests have less than 1ms of execution time after which they pause. They only resume execution after I make another request to the server.

This is my webhook handler:

export const POST: RequestHandler = async ({ request, locals, fetch }) => {
  console.log('event received');
  const body = await request.text();
  const signature = request.headers.get('stripe-signature') ?? '';

  let event;

  try {
    event = stripe.webhooks.constructEvent(body, signature, STRIPE_WEBHOOK_SECRET);
  } catch (err: any) {
    console.warn('⚠️  Webhook signature verification failed.', err.message);

    return new Response(undefined, { status: 400 });
  }

  switch (event.type) {
    case 'payment_intent.succeeded':
      const intent = event.data.object;
      const items: String[] = JSON.parse(intent.metadata.items);
      for (const item of items) {
        const [region, type, limit, quantity] = item.split('-');
        createEsimWithRetry(
          locals.supabase,
          intent.metadata.email,
          region,
          type,
          limit,
          quantity,
          intent.metadata.locale
        );
      }
      break;
  }

  return new Response(undefined);
};

Here createEsimWithRetry is the long running function. I am not awaiting it since stripe requires us to send a response immediately.

I have attached two screenshots, one for the logs and one for the function invocation information. As you can see, we have the initial webhook getting called at 15:56. Then I have to call multiple other requests, each of them showing an execution duration of under 500ms. Then finally at 16:02, we get the final part of the function (sent email).


Sveltekit 2.19 with adapter-auto
Node 20.x
Function Max Duration is set to 300s.
Fluid compute is disabled