Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangfire throws ObjectDisposedException during twice Dispose for BackgroundProcessingServer #2488

Open
MiErnst opened this issue Dec 17, 2024 · 0 comments

Comments

@MiErnst
Copy link

MiErnst commented Dec 17, 2024

The last comment in #2097 mentions that it should be fixed, but I'm still running into this issue when executing integration tests with a custom WebApplicationFactory. The service was simply registered using the WebApplicationBuilder (builder.Services.AddHangfireServer()).

I'm using version 1.8.17.

[Test Class Cleanup Failure (Foo.Tests.MyTest)]: System.ObjectDisposedException : Cannot access a disposed object.
Object name: 'Hangfire.Server.BackgroundProcessingServer'.
at Hangfire.Server.BackgroundProcessingServer.ThrowIfDisposed() in C:\projects\hangfire-525\src\Hangfire.Core\Server\BackgroundProcessingServer.cs:line 265
   at Hangfire.Server.BackgroundProcessingServer.SendStop() in C:\projects\hangfire-525\src\Hangfire.Core\Server\BackgroundProcessingServer.cs:line 128
   at Hangfire.BackgroundJobServer.SendStop() in C:\projects\hangfire-525\src\Hangfire.Core\BackgroundJobServer.cs:line 150
   at Hangfire.BackgroundJobServerHostedService.StopAsync(CancellationToken cancellationToken) in C:\projects\hangfire-525\src\Hangfire.NetCore\BackgroundJobServerHostedService.cs:line 128
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.StopAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.DisposeAsync()
   at Foo.Tests.IntegrationTests.Tests.Base.TestApplicationFactory`1.DisposeAsync() in /azp/_work/1/s/tests/Foo.Tests/IntegrationTests/Tests/Base/TestApplicationFactory.cs:line 29
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.Dispose(Boolean disposing)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants