Azure / Azure/azure-functions-host

Throwing exception with null message in non-HTTP trigger causing functions host crash

Open
#8,069 6 comments 0 reactions 2 assignees Claimed by @v-bbalaiagar View on GitHub
needs-investigation
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

Throwing exception with null message in non-HTTP trigger causing functions host crash.

This is the related log from local debug func tool.

```
[2022-01-17T13:19:29.939Z] Executing 'NullMessageExceptionInQueue' (Reason='New queue message detected on 'test-exception-queue'.', Id=e891a2b4-f1df-4711-8e4c-090d8300617f)
[2022-01-17T13:19:29.940Z] Trigger Details: MessageId: 5afed3b7-1b0a-44a8-acd6-8a382878270b, DequeueCount: 1, InsertedOn: 2022-01-17T13:19:28.000+00:00
[2022-01-17T13:19:30.657Z] Host lock lease acquired by instance ID '000000000000000000000000618DFF3B'.
[2022-01-17T13:19:31.064Z] An unhandled exception has occurred. Host is shutting down.
[2022-01-17T13:19:31.065Z] Microsoft.Azure.WebJobs.Script: Object reference not set to an instance of an object.
```

#### Repro steps

Calling function NullMessageException and wait for crash.

```csharp
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace MyFunctions
{
public static class NullMessageException
{
[FunctionName("NullMessageException")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Queue("test-exception-queue", Connection = "AzureWebJobsStorage")] IAsyncCollector queue,
ILogger log)
{
await queue.AddAsync("hello");
await queue.FlushAsync();
return new AcceptedResult();
}

[FunctionName("NullMessageExceptionInQueue")]
public static async Task Run2(
[QueueTrigger("test-exception-queue", Connection = "AzureWebJobsStorage")] string exceptionQueue,
ILogger log)
{
await Task.Delay(1000);
throw new CustomException();
}

private class CustomException : Exception
{
public override string Message => null;
}
}
}
```

#### Expected behavior

Poisoning the queue item.

#### Actual behavior

Function host crashed.

#### Related information

I found this by instantiating a Microsoft.Azure.Cosmos.CosmosException with null message and then throw, this takes me two days to understand why my code caused tools host to crash...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.