Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Description

WatchAnySubscribersAsync was throwing NotSupportedException when the async enumerator was disposed. The method subscribed to nested events (LoggerAddedOnSubscribersChanged) but only cleaned up the outer subscription in the finally block, leaving inner event handlers dangling.

Changes:

  • Track all OnSubscribersChanged event handler subscriptions in a list
  • Unsubscribe from all tracked handlers in the finally block before completing the channel
// Before: Lambda subscription was never cleaned up
state.OnSubscribersChanged += (hasSubscribers) => { ... };

// After: Handler is tracked and explicitly unsubscribed
Action<bool> handler = (hasSubscribers) => { ... };
state.OnSubscribersChanged += handler;
subscribedStates.Add((state, handler));
// ... later in finally block ...
foreach (var (state, handler) in subscribedStates)
{
    state.OnSubscribersChanged -= handler;
}

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No
Original prompt

Investigate ths:

System.NotSupportedException : Specified method is not supported. at Aspire.Hosting.ApplicationModel.ResourceLoggerService.WatchAnySubscribersAsync(CancellationToken cancellationToken)+System.IAsyncDisposable.DisposeAsync()
at Microsoft.AspNetCore.InternalTesting.AsyncTestHelpers.DefaultTimeout[T](IAsyncEnumerable1 asyncEnumerable, Int32 milliseconds, String filePath, Int32 lineNumber)+MoveNext() in /Users/runner/work/aspire/aspire/tests/Shared/AsyncTestHelpers.cs:line 60 at Microsoft.AspNetCore.InternalTesting.AsyncTestHelpers.DefaultTimeout[T](IAsyncEnumerable1 asyncEnumerable, Int32 milliseconds, String filePath, Int32 lineNumber)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Aspire.Hosting.Tests.Dashboard.DashboardLifecycleHookTests.WatchDashboardLogs_WrittenToHostLoggerFactory(Nullable1 timestamp, String logMessage, String expectedMessage, String expectedCategory, LogLevel expectedLevel) in /Users/runner/work/aspire/aspire/tests/Aspire.Hosting.Tests/Dashboard/DashboardLifecycleHookTests.cs:line 51 at Aspire.Hosting.Tests.Dashboard.DashboardLifecycleHookTests.WatchDashboardLogs_WrittenToHostLoggerFactory(Nullable1 timestamp, String logMessage, String expectedMessage, String expectedCategory, LogLevel expectedLevel) in /Users/runner/work/aspire/aspire/tests/Aspire.Hosting.Tests/Dashboard/DashboardLifecycleHookTests.cs:line 51
--- End of stack trace from previous location ---

StdOut

| [2025-12-18T18:08:40] Aspire.Hosting.ApplicationModel.ResourceNotificationService Trace: Version: 1 Resource aspire-dashboard/aspire-dashboard-qgvxmrva update published: ResourceType = Executable, CreationTimeStamp = (null), State = { Text = (null), Style = (null) }, IsHidden = True, HeathStatus = (null), ResourceReady = False, ExitCode = (null), Urls = { }, EnvironmentVariables = { }, Properties = { }, HealthReports = { }, Commands = { }


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 18, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13644

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13644"

…t subscriptions

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate System.NotSupportedException in ResourceLoggerService Fix NotSupportedException in ResourceLoggerService.WatchAnySubscribersAsync disposal Dec 18, 2025
Copilot AI requested a review from davidfowl December 18, 2025 19:43
@davidfowl davidfowl requested a review from JamesNK December 19, 2025 01:24
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.

2 participants