Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

ServiceBusConnection has already been closed. Please create a new instance #114

@ThomasArdal

Description

@ThomasArdal

I have recently added Microsoft.Extensions.Logging to my Azure Functions. This reveals a range of different errors logged from the runtime as well as bindings. I'm creating GitHub issues when I see a new error, to try and understand if each error is something I should take seriously or not. I generally think that Azure Functions log way too many errors internally. The general answer here on GitHub is that "you can ignore that error". Logging errors that can simply be ignored is a bad practice IMO since important errors disappear in a large amount of logged errors.

For today's error, I'm seeing this:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ServiceBusConnection has already been closed. Please create a new instance'.
   at Microsoft.Azure.ServiceBus.ServiceBusConnection.ThrowIfClosed()
   at Microsoft.Azure.ServiceBus.ClientEntity.ThrowIfClosed()
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.AbandonAsync(String lockToken, IDictionary`2 propertiesToModify)
   at Microsoft.Azure.ServiceBus.MessageReceivePump.AbandonMessageIfNeededAsync(Message message)

For this function, I have a ServiceBus input binding like this:

public async Task Run([ServiceBusTrigger("%topicName%", "%subscriptionName%", Connection = "connection")]string mySbMsg)

The mySbMsg variable is parsed like this:

JsonConvert.DeserializeObject<UptimeResultMessage>(mySbMsg, new JsonSerializerSettings())

No further requests are made to Azure ServiceBus in the function.

This error seems to be something happening internally in either the runtime or the binding. Can this error be ignored? Should it even be logged?

Sorry for the semi-rant here, but when we are drowning in errors from the runtime, getting a good overview of the log is hard.

I'm running on .NET Core 3.1 on Azure Functions v3 and have the following NuGet packages installed:

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions