ServiceEndpointWatcher logs normal cancellation as an error
Maintainers usually reply within 1 day
@seragAhmed is already working on this.
Since Nov 12, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- backend, observability-sre
Research direction
Start with src/Libraries/Microsoft.Extensions.ServiceDiscovery/ServiceEndpointWatcher.cs, especially DisposeAsync and RefreshAsyncInternal, which the issue identifies as the cancellation and logging path. Check the existing ServiceEndpointWatcher tests for coverage of disposal during a background refresh. Done means this normal cancellation no longer logs a resolution error, with a test covering the repro.
Written by the indexing model from the issue text.
Description
Description
Hi!
I'm getting Error resolving endpoints for service ... when a watcher is disposed during a background refresh. The refresh is cancelled by the watcher itself, but that cancellation ends up in the error log.
I ran into this with DNS discovery. The first lookup worked, then a background refresh was left waiting for a DNS response. About 20 seconds after the lookup, idle-watcher cleanup cancelled it and logged TaskCanceledException. The next lookup worked too.
Reproduction Steps
Here is a smaller repro with a custom provider, so there is no DNS server to set up.
Create a .NET 10 console app and add Microsoft.Extensions.ServiceDiscovery 10.11.0 and a framework reference to Microsoft.AspNetCore.App. Replace Program.cs with:
using System.Diagnostics.CodeAnalysis;
using System.Net;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ServiceDiscovery;
var factory = new SlowRefreshProvider();
var services = new ServiceCollection();
services.AddLogging(logging => logging.AddSimpleConsole());
services.AddServiceDiscoveryCore(options => options.RefreshPeriod = TimeSpan.FromMilliseconds(100));
services.AddSingleton<IServiceEndpointProviderFactory>(factory);
await using var provider = services.BuildServiceProvider();
var resolver = provider.GetRequiredService<ServiceEndpointResolver>();
await resolver.GetEndpointsAsync("http://sample", CancellationToken.None);
await factory.RefreshStarted.Task.WaitAsync(TimeSpan.FromSeconds(5));
Console.WriteLine("Disposing the resolver during a background refresh");
await resolver.DisposeAsync();
Console.WriteLine("Disposed successfully");
sealed class SlowRefreshProvider : IServiceEndpointProviderFactory, IServiceEndpointProvider
{
private int calls;
public TaskCompletionSource RefreshStarted { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public bool TryCreateProvider(ServiceEndpointQuery query, [NotNullWhen(true)] out IServiceEndpointProvider? provider)
{
provider = this;
return true;
}
public async ValueTask PopulateAsync(IServiceEndpointBuilder endpoints, CancellationToken cancellationToken)
{
if (Interlocked.Increment(ref calls) == 1)
{
endpoints.Endpoints.Add(ServiceEndpoint.Create(new DnsEndPoint("localhost", 8080)));
return;
}
RefreshStarted.SetResult();
await Task.Delay(Timeout.InfiniteTimeSpan, cancellationToken);
}
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
Run with dotnet run. The first lookup succeeds. Once the background refresh starts, the example disposes the resolver. The provider uses the supplied cancellation token and doesn't throw anything on its own.
Expected behavior
I'd expect cancellation during disposal to be handled without logging a resolution error.
Actual behavior
Disposing the resolver during a background refresh
fail: Microsoft.Extensions.ServiceDiscovery.ServiceEndpointWatcher[4]
Error resolving endpoints for service 'http://sample'.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at SlowRefreshProvider.PopulateAsync(...)
at Microsoft.Extensions.ServiceDiscovery.ServiceEndpointWatcher.RefreshAsyncInternal()
Disposed successfully
Regression?
No response
Known Workarounds
No response
Configuration
Tested with package 10.11.0, .NET SDK 10.0.403, macOS arm64.
Other information
From the watcher source for 10.11.0, this seems to happen because DisposeAsync cancels _disposalCancellation, and RefreshAsyncInternal logs the resulting exception as ResolutionFailed. Disposal suppresses the exception afterwards, but the error has already been logged.
The same catch/log path is still in main. I haven't tested an 11.x package.
- Dominant language
- C#
- Stars
- 3.3k
- Forks
- 919
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 35
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/extensions
-
area-ai untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dotnet/extensions#7956 ·
Maintainers usually reply within 1 day
-
area-ai bug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dotnet/extensions#7954 ·
Maintainers usually reply within 1 day
-
OpenAISpeechToTextClient sends Ogg MemoryStream audio with an .mp3 filenamePossibly taken @Manish-1kumar claimed this 17 days ago. Openarea-ai untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/extensions#7900 · 1 comment ·
Maintainers usually reply within 1 day
-
Unable to obtain the UsageContent and FinishReason of response.incompletePossibly taken @jaeminbird claimed this 20 days ago. Openarea-ai bug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
dotnet/extensions#7893 ·
Maintainers usually reply within 1 day
-
AI Chat Web template: scaffolded Identity pages are inaccessible because App.razor applies an interactive render mode unconditionallyPossibly taken @valkiara claimed this 20 days ago. Openarea-ai-templates untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/extensions#7889 · 1 comment ·
Maintainers usually reply within 1 day
All issues in dotnet/extensions
Similar issues
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area/backend type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
umbraco/Umbraco-CMS#24668 · 1 comment ·
Maintainers usually reply within 1 day
-
Pri3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
MicrosoftDocs/windows-dev-docs#6205 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day