Skip to content

Unsubscribe PriorityChanged in WebServiceGroup.Clear() - #56

Open
ImanEstiri wants to merge 1 commit into
Garados007:mainfrom
ImanEstiri:fix-webservice-clear
Open

ImanEstiri wants to merge 1 commit into
Garados007:mainfrom
ImanEstiri:fix-webservice-clear

Conversation

@ImanEstiri

Copy link
Copy Markdown

Closes #45

What this changes

WebServiceGroup.Clear() now unsubscribes every contained service from
PriorityChanged before clearing the internal list, matching what
Remove() and WebServiceCollection.Clear() already do.

Why

Without the unsubscribe, a cleared service kept a live handler reference
to the group (a memory leak), and changing its own Priority re-added it
to the group via Services.ChangePriority() — so a "cleared" group could
silently regain services it no longer owned.

Testing

  • dotnet build -c Release passes on both net8.0 and net10.0
  • dotnet test --filter "FullyQualifiedName~TestWebServiceGroup" passes
  • Added TestWebServiceGroup with two regression tests:
    • TestClearDetachesFromPriorityChanged — fails without the fix, passes with it
    • TestRemoveDetachesFromPriorityChanged — pins the pre-existing behaviour of
      Remove() so the two paths cannot drift apart later

Note on unrelated test failure

Running the full dotnet test locally shows
TestSecureWebServerDropsAStalledConnectionThatNeverSendsAnything
(both target frameworks) failing after its 5-second wait. This is an SSL
handshake-timeout test, unrelated to this change, and it reproduces on a clean
main checkout without my changes applied. I left it untouched in this PR.

Clear() emptied the internal list but left every service's
PriorityChanged handler attached, unlike Remove() and
WebServiceCollection.Clear(). A service removed this way was kept
alive by the group's handler (a leak), and re-prioritising itself
put it back into the list via Services.ChangePriority().

Fixes Garados007#45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebServiceGroup.Clear leaves services subscribed to the group

1 participant