简体   繁体   中英

Azure function's http trigger is giving 500 internal server error

i have an http trigger with an output binding of CosmosDB (sql api) that gives 500 internal server error when i make a POST call on to the deployed version.

 public static class Function1
{
    [FunctionName("Function1")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] Request req,

  ILogger log, [CosmosDB(
            databaseName: "haveThatDB",
            collectionName: "Requests",
            ConnectionStringSetting = "CosmosDBConnection",CreateIfNotExists =true)] IAsyncCollector<Request> requestOutput
       )
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        await requestOutput.AddAsync(req);



        return req != null
            ? (ActionResult)new OkObjectResult($"Hello, {req.ItemRequested}")
            : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
    }
}

the same code works fine locally.

no logs are generated in KUDU and in the portal for the failed requests. if i remove the cosmosDB binding it works locally (i can see document being created) and in deployed url as well, and success logs are also generated.

However once i was able to observe some error message like "Error parsing boolean value. Path '', line 1, position 1." but after that i was never able to see this problem in logs. because there are no logs in case of 500 internal server error. activating app insights also doesn't shows any failed 500 hit being made.

在此处输入图片说明

Without further info, I assume you may forget to add CosmosDBConnection in Application settings on portal because your code works on my side both locally and online. Settings in local.settings.json are not inserted to portal as they are used for local dev.

I have been trying to implement a Tutorial in MS Learning for add-bookmark function and I found that whenever I add the Output binding of CosmosDB, then it fails to process and it generates the same 500-Internal Error. Even it fails when the ID specified in the input parameter on Testing is not found in the CosmosDB.

The Code+Test panel on Azure Portal also shows below logs which doesn't give any clue what is wrong with the request.

2020-08-05T06:05:43Z   [Information]   Executing 'Functions.add-bookmark' (Reason='This function was programmatically called via the host APIs.', Id=b6b6617d-c1d6-4729-91c9-c0d5f18ddc1b)
2020-08-05T06:05:43Z   [Verbose]   Sending invocation id:b6b6617d-c1d6-4729-91c9-c0d5f18ddc1b
2020-08-05T06:05:43Z   [Verbose]   Posting invocation id:b6b6617d-c1d6-4729-91c9-c0d5f18ddc1b on workerId:70d0b104-cdf6-4ad9-b2ac-d7e079b80544
2020-08-05T06:05:43Z   [Error]   Executed 'Functions.add-bookmark' (Failed, Id=b6b6617d-c1d6-4729-91c9-c0d5f18ddc1b, Duration=102ms)

Since I had the same CosmosDB account as Input Binding as well, I was sure that the CosmosDB Connection was not the issue.

Then I went on to change a few Runtime parameters. After playing with a couple of them, once I changed the RunTime version to ~2, it started working fine.

I am still not sure why Runtime 3.0 doesn't work, There is already a BUG https://github.com/Azure/Azure-Functions/issues/1670 open with Azure Functions team on Github.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM