Skip to content

Fix background thread leaks from rejected worker construction - #143

Merged
FlorianRappl merged 1 commit into
AngleSharp:develfrom
EvotecIT:feature/worker-startup-cleanup
Oct 4, 2026
Merged

FlorianRappl merged 1 commit into
AngleSharp:develfrom
EvotecIT:feature/worker-startup-cleanup

Conversation

@PrzemyslawKlys

Copy link
Copy Markdown
Contributor

Creating a Worker in a context without a document loader throws NotSupportedError, but the constructor previously started a background event loop before checking that requirement. Catching repeated construction failures therefore left one unreachable thread per attempt.

Validate the parent's loader and resolve the source before allocating the worker loop. Dispose the partially created context and loop if subsequent construction or scheduling fails. Successful startup and message delivery keep their existing behavior.

Validation: the regression fails against the original code with 32 surviving threads; the complete .NET 10 suite passes (302 tests), and all six worker tests pass on .NET Framework 4.7.2.

@FlorianRappl FlorianRappl added this to the v1.1.1 milestone Oct 4, 2026

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@FlorianRappl
FlorianRappl merged commit f84f18d into AngleSharp:devel Oct 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants