Azure function app running indefinitely on webhook trigger

Ramji R 11 Reputation points
The Below function app code should execute while a webhook is triggered. The below code runs fine. But eventhough the webhook is triggered once. The below code runs indefinitely. Is anything is wrong in the below code which cause the issue.


    module.exports = async (context, req) => {
      context.log("JavaScript HTTP trigger function processed a request.");
      const contentful = require("contentful-management");
      const client = contentful.createClient({
        accessToken: "test",
      const spaceId = "test";
      const environmentId = "test";
      try {
        const space = await client.getSpace(spaceId);
        const environment = await space.getEnvironment(environmentId);
        let response = await environment.getEntry(;
        const firstEntry = response;
        if (
          firstEntry.fields.previousSlug != undefined &&
          firstEntry.fields.slug != firstEntry.fields.previousSlug
        ) {
          const testingContentTypeId = "redirectManager"; // Replace with the actual content type ID
          const testingEntry = await environment.createEntry(testingContentTypeId, {
            fields: {
              id: { "en-GB": firstEntry.fields.internalDocumentId["en-GB"] },
              redirectSlug: {
                "en-GB": firstEntry.fields.previousSlug["en-GB"],
              currentSlug: { "en-GB": firstEntry.fields.slug["en-GB"] },
        firstEntry.fields.previousSlug = firstEntry.fields.slug;
        var result = await firstEntry.update();
        await result.publish();
      } catch (error) {
        context.res = {
          body: error,
        return "test";


      "bindings": [
          "authLevel": "function",
          "type": "httpTrigger",
          "direction": "in",
          "name": "req",
          "methods": [
          "type": "http",
          "direction": "out",
          "name": "res"

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,691 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MikeUrnun 8,341 Reputation points

    Hello @Ramji R - Thanks for reaching out. The bindings look OK, and the function signature and the return also look OK to me. However, I do have the following questions for you which might help troubleshoot the root cause:

    • Does the lazyloading const contentful = require("contentful-management"); inside the function (instead of being at the top) work as intended and the client object is created successfully? Note that require() is a synchronous call and can block the rest of the execution.
    • Do you get any explicit error messages when pulling a Diagnostics report?
    • If you suspect that the issue is within the code, could you try to reproduce & debug locally?
    • If the issue occurs only on Azure, could you configure a Profiler through Application Insights and see if it provides any insights?

    Please "Accept Answer" if the answer is helpful so that others in the community may benefit from your experience.

    0 comments No comments