ServiceEndpointWatcher logs normal cancellation as an error
Los mantenedores suelen responder en 1 día
@seragAhmed ya está trabajando en esto.
Desde el 12/11/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- csharp
- Área
- backend, observability-sre
Línea de trabajo
Empieza por src/Libraries/Microsoft.Extensions.ServiceDiscovery/ServiceEndpointWatcher.cs, especialmente DisposeAsync y RefreshAsyncInternal, que el issue identifica como la ruta de cancelación y registro. Comprueba si las pruebas existentes de ServiceEndpointWatcher cubren la eliminación durante una actualización en segundo plano. Se considerará terminado cuando esta cancelación normal ya no registre un error de resolución y haya una prueba que cubra la reproducción.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C#
- Estrellas
- 3.3k
- Forks
- 919
- Merge medio
- 2 d 2 h
- PR fusionados (30 d)
- 35
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/extensions
-
area-ai untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/extensions#7956 ·
Los mantenedores suelen responder en 1 día
-
area-ai bug untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/extensions#7954 ·
Los mantenedores suelen responder en 1 día
-
OpenAISpeechToTextClient sends Ogg MemoryStream audio with an .mp3 filenamePosiblemente ocupada @Manish-1kumar la tomó hace 17 días. Abiertoarea-ai untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/extensions#7900 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Unable to obtain the UsageContent and FinishReason of response.incompletePosiblemente ocupada @jaeminbird la tomó hace 20 días. Abiertoarea-ai bug untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
dotnet/extensions#7893 ·
Los mantenedores suelen responder en 1 día
-
AI Chat Web template: scaffolded Identity pages are inaccessible because App.razor applies an interactive render mode unconditionallyPosiblemente ocupada @valkiara la tomó hace 20 días. Abiertoarea-ai-templates untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
dotnet/extensions#7889 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/extensions
Issues similares
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
area/backend type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
umbraco/Umbraco-CMS#24668 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Pri3
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
MicrosoftDocs/windows-dev-docs#6205 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día