Website down due to timeout 504 in Edge Function

Hi, we’re having problems with an edge function, it was working properly for weeks, and suddenly every page behind it starts timing out with a 504. Removing it made everything work properly again.

The function is nothing special, just a simple string replace in the content through a regex so I don’t think it is to blame, but here it is anyway:

import { Context } from '';

export default async (request: Request, context: Context) => {
  // Get the page content
  const response = await;
  const page = await response.text();

  // Replace the placeholder with country name
  const regex = /\{\{NETLIFY_EDGE_FUNC_COUNTRY\}\}/;
  const countryName =;
  const updatedPage = page.replace(regex, countryName ? 'in ' + countryName : 'everywhere');
  return new Response(updatedPage, response);

The culprit seems to be Netlify itself, as the bug would go away and come back on its own. I have a test page where I still use the edge function and can share it with whoever wants to investigate this, but at the moment the bug seems to not be happening.

Hi @fvieira,

We have identified a problem residing in an upstream service that is causing these timeouts. Presently we are working with the provider on this issue and are waiting for a code fix from them. We apologize for the inconvenience and are doing as much as we can to aid the provider in the restoration of service.

Thank you @hrishikesh, please just let us know when it’s safe to use edge functions again.

As of today, these timeout issues have been resolved (they were resolved about 5 days ago), now you’ll only see a timeout error when it actually times out due to user-written code. Let us know if you’re still experiencing issues.

1 Like

Thank you very much, I’ll try it out when we decide to enable the edge functions again.