Skip to content

BackgroundService with ExecuteAsync Task appears to eat exception #117014

Open
@regalialong

Description

@regalialong

Description

#116283 recently has changed BackgroundService to run ExecuteAsync in a Task to avoid BackgroundServices blocking the host on startup, which I'm very excited about. I've copied the new implementation into my project since it's a relatively small and isolated change and there isn't a preview release of Microsoft.Extensions.Hosting with it yet (yes I know, I know).

My app appeared to stop throwing exceptions after using the new implementation, and chasing it in the debugger, I've noticed this wasn't related to my code anymore.
I think the PR may have introduced a behavior change unintentionally.

Reproduction Steps

ServicesExceptionTest.zip

Run this project, OldWorker (which uses the old implementation from Microsoft.Extensions.Hosting v9.0.6) will throw.

Comment out Line 3 to not include OldWorker in the host, NewWorker (which uses the copied Task BackgroundService implementation) doesn't throw.

Expected behavior

BackgroundService.ExecuteAsync should bubble up exceptions.

Actual behavior

BackgroundService.ExecuteAsync silently ignores exceptions, the host continues as normal.

Regression?

Works with Microsoft.Extensions.Hosting 9.0.6 which doesn't include #116283 yet

Known Workarounds

No response

Configuration

Microsoft.NETCore.App 9.0.4 on Arch Linux x64bit
Probably not configuration related

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions