Azure / Azure/azure-functions-host

.NET6 isolated ServiceBusTrigger function failing with "Container is disposed and should not be used: Container is disposed"

Open
#8,223 2 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

We are running a few .NET6 Azure Function apps in isolated mode and I noticed that from time to time some Service Bus messages go to DLQ without any apparent reason or related logs. The messages simply fail and don't even show in the execution list of the function as failed.

Digging into the Azure Insight logs I found the message "Container is disposed and should not be used: Container is disposed" in the requests table (I found it by the timestamp of the failed message). While researching the problem I found the issue #5240 and I think I understand what is happening. But this is very bad. My code was never called and the message was put in DLQ for no good reason.

As I understood, there is a "drain mode", but I couldn't find any information on how to set it up and use, specially for Azure Functions in isolated mode. I saw something about CancellationTokens, but this is not really and option for ServiceBusTrigger in .NET6 isolated, as we don't get the full message object and we don't have full control over the success or error when processing the message.

Is this being addressed in the SDKs? Is there any guidance or workarounds to mitigate the problem?

If necessary, I can provide further info.

- Timestamp: 2022-03-08T18:05:42..9253468-03:00
- Invocation ID: 33d2ce29-1ac7-4f39-817f-8eb56dbd6119
- Operation ID: 97b3d082998991d7aa1fe2d28cb0aafe
- Region: Brazil South

Our app is running
- .NET6 in Isolated mode
- Microsoft Azure Functions Worker 1.6.0
- Microsoft Azure Functions Worker SDK 1.3.0
- Microsoft Azure Functions Worker Extensions ServiceBus 4.2.1

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.