azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

Getting the error "Container is disposed and should not be used exception" intermittently after .NET 8 upgrade and change to Azure Durable Function Isolated model

Open BrunoCandia opened this issue 1 year ago • 0 comments

Is your question related to a specific version? If so, please specify:

We are using: -C# with .Net 8, -Azure function v4, -Isolated model -Service bus trigger -Service plan: Windows / Elastic plan

Here are the nuget packages I use:

image

I found the following exception in the log for an Azure Function in production environment:

---> DryIoc.ContainerException: Container is disposed and should not be used: Container is disposed. sbt-tenant-notifications/Subscriptions/SendRecordTrackingInfoEvent-d91645d7-7ca4-4995-bd82-73c41feab5ab: User message handler complete: Message: SequenceNumber: 228486, Exception: Microsoft.Azure.WebJobs.Script.HostDisposedException: The host is disposed and cannot be used. Disposed object: 'Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.ScopedResolver'; Found IListener in stack trace: 'Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener, Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.16.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' You may include Dispose stack-trace into the message via: container.With(rules => rules.WithCaptureContainerDisposeStackTrace()) at DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3) in //src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:line 9002 at DryIoc.Container.ThrowIfContainerDisposed() in //src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:line 411 at DryIoc.Container.WithCurrentScope(IScope scope, Boolean preferInterpretaion) in //src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:line 437 at DryIoc.ResolverContext.OpenScope(IResolverContext r, Object name, Boolean trackInParent, Boolean preferInterpretation) in //src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:line 2709 at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.ScopedResolver.CreateChildScope(IServiceScopeFactory rootScopeFactory) in //src/WebJobs.Script.WebHost/DependencyInjection/ScopedResolver.cs:line 42 at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.JobHostServiceProvider.CreateScope() in //src/WebJobs.Script.WebHost/DependencyInjection/JobHostServiceProvider.cs:line 106 --- End of inner exception stack trace --- at Microsoft.Azure.WebJobs.Script.HostDisposedException..ctor(String disposedObjectName, Exception inner) in //src/WebJobs.Script/HostDisposedException.cs:line 24 at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.JobHostServiceProvider.CreateScope() in //src/WebJobs.Script.WebHost/DependencyInjection/JobHostServiceProvider.cs:line 106 at Microsoft.Azure.WebJobs.Host.Executors.DefaultInstanceServicesProvider.get_InstanceServices() in D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\DefaultInstanceServicesProvider.cs:line 26 at Microsoft.Azure.WebJobs.Host.Executors.FunctionInstance.get_InstanceServices() in D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInstance.cs:line 56 at Microsoft.Azure.WebJobs.Host.Bindings.FunctionBindingContext..ctor(IFunctionInstanceEx functionInstance, CancellationToken functionCancellationToken) in D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Bindings\FunctionBindingContext.cs:line 66 at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 279 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 108 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutorExtensions.TryExecuteAsync(IFunctionExecutor executor, Func1 instanceFactory, ILoggerFactory loggerFactory, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutorExtensions.cs:line 50 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutorExtensions.TryExecuteAsync(IFunctionExecutor executor, Func1 instanceFactory, ILoggerFactory loggerFactory, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.Host.Executors.TriggeredFunctionExecutor1.TryExecuteAsync(TriggeredFunctionData input, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\TriggeredFunctionExecutor.cs:line 59 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.WebJobs.Host.Executors.TriggeredFunctionExecutor1.TryExecuteAsync(TriggeredFunctionData input, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener.ProcessSessionMessageAsync(ProcessSessionMessageEventArgs args) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener.ProcessSessionMessageAsync(ProcessSessionMessageEventArgs args) at Azure.Messaging.ServiceBus.ServiceBusProcessor.OnProcessSessionMessageAsync(ProcessSessionMessageEventArgs args) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Azure.Messaging.ServiceBus.ServiceBusProcessor.OnProcessSessionMessageAsync(ProcessSessionMessageEventArgs args) at Azure.Messaging.ServiceBus.ServiceBusSessionProcessor.OnProcessSessionMessageAsync(ProcessSessionMessageEventArgs args) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Azure.Messaging.ServiceBus.ServiceBusSessionProcessor.OnProcessSessionMessageAsync(ProcessSessionMessageEventArgs args) at Azure.Messaging.ServiceBus.SessionReceiverManager.OnMessageHandler(EventArgs args) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Azure.Messaging.ServiceBus.SessionReceiverManager.OnMessageHandler(EventArgs args) at Azure.Messaging.ServiceBus.ReceiverManager.ProcessOneMessage(ServiceBusReceivedMessage triggerMessage, CancellationToken cancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Azure.Messaging.ServiceBus.ReceiverManager.ProcessOneMessage(ServiceBusReceivedMessage triggerMessage, CancellationToken cancellationToken) at Azure.Messaging.ServiceBus.ReceiverManager.ProcessOneMessageWithinScopeAsync(ServiceBusReceivedMessage message, String activityName, CancellationToken cancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Azure.Messaging.ServiceBus.ReceiverManager.ProcessOneMessageWithinScopeAsync(ServiceBusReceivedMessage message, String activityName, CancellationToken cancellationToken) at Azure.Messaging.ServiceBus.SessionReceiverManager.ReceiveAndProcessMessagesAsync(CancellationToken processorCancellationToken) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task1.TrySetResult(TResult result) at Azure.Messaging.ServiceBus.ServiceBusReceiver.ReceiveMessagesAsync(Int32 maxMessages, Nullable1 maxWaitTime, Boolean isProcessor, CancellationToken cancellationToken) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task1.TrySetResult(TResult result) at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsync(Int32 maxMessages, Nullable1 maxWaitTime, CancellationToken cancellationToken) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task1.TrySetResult(TResult result) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.SetExistingTaskResult(Task1 task, TResult result) at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder1.SetResult(TResult result) at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task1.TrySetResult(TResult result) at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<>c.<<ReceiveMessagesAsync>b__44_0>d.MoveNext() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task1.TrySetResult(TResult result) at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsyncInternal(Int32 maxMessages, Nullable1 maxWaitTime, TimeSpan timeout, CancellationToken cancellationToken) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task1.TrySetResult(TResult result) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) at System.Threading.Tasks.TaskFactory1.<>c__DisplayClass38_0`1.<FromAsyncImpl>b__0(IAsyncResult iar) at Microsoft.Azure.Amqp.AsyncResult.TryComplete(Boolean didCompleteSynchronously, Exception exception) at Microsoft.Azure.Amqp.AsyncResult.Complete(Boolean didCompleteSynchronously, Exception e) at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() at System.Threading.Thread.StartCallback() , LockToken: d55934c4-0fa8-47ce-8963-9dbb4ee66f1f

Question

How this issue could be fixed or get a clue where is the issue?

BrunoCandia avatar Sep 17 '24 20:09 BrunoCandia