Skip to content

ObjectDisposedException intermittently crashes test process from DefaultHttpClientFactory.ExpiryTimer_Tick #90386

@martincostello

Description

@martincostello

Description

I have some repositories that I've hooked up to ingest the daily builds of .NET 8. In this morning's update I have two repos (one public, one private) where the existing test suite is starting to fail due to this error:

The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Http.DefaultHttpClientFactory.<.ctor>b__14_1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.Extensions.Http.DefaultHttpClientFactory.ExpiryTimer_Tick(Object state)
   at Microsoft.Extensions.Http.ActiveHandlerTrackingEntry.Timer_Tick()
   at Microsoft.Extensions.Http.ActiveHandlerTrackingEntry.<>c.<.cctor>b__22_0(Object s)
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

It appears that something running in the background for HttpClientFactory is trying to use the service provider after it's torn down and throwing an exception. This doesn't seem to happen 100% of the time though based on the attempts for this workflow run where macOS passes every time, Windows and Linux fail twice, and then all three pass.

Edit: Fails on macOS too in a third repo

Reproduction Steps

Clone martincostello/alexa-london-travel-site@74309e7 and run build.ps1 in the root of the repository.

Expected behavior

The tests pass.

Actual behavior

The tests sometimes crashes with the above error on Linux and Windows.

Regression?

Yes.

Known Workarounds

No response

Configuration

  • .NET SDK 8.0.100-rc.1.23410.12
  • Microsoft.AspNetCore.* 8.0.0-rc.1.23410.15

Other information

Maybe have been introduced by #89531.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions