ServiceEndpointWatcher logs normal cancellation as an error
维护者通常 1 天内回复
@seragAhmed 已经在做这个了。
开始于 2026年11月12日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- csharp
调研方向
从 src/Libraries/Microsoft.Extensions.ServiceDiscovery/ServiceEndpointWatcher.cs 开始,重点检查 DisposeAsync 和 RefreshAsyncInternal,issue 将它们指出为取消和日志记录路径。检查现有的 ServiceEndpointWatcher 测试是否覆盖了后台刷新期间的释放情况。完成标准是这种正常取消不再记录解析错误,并且有一个测试覆盖该复现问题。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C#
- 星标
- 3.3k
- 派生
- 919
- 平均合并
- 2 天 2 小时
- 30 天内合并 PR
- 35
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/extensions 的其他 Issue
-
area-ai untriaged
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/extensions#7956 ·
维护者通常 1 天内回复
-
area-ai bug untriaged
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/extensions#7954 ·
维护者通常 1 天内回复
-
OpenAISpeechToTextClient sends Ogg MemoryStream audio with an .mp3 filename可能已有人在做 @Manish-1kumar 于 17 天前认领。 未关闭area-ai untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/extensions#7900 · 1 条评论 ·
维护者通常 1 天内回复
-
Unable to obtain the UsageContent and FinishReason of response.incomplete可能已有人在做 @jaeminbird 于 20 天前认领。 未关闭area-ai bug untriaged
难度 2/5 1-3 小时 新手友好度 67/100
dotnet/extensions#7893 ·
维护者通常 1 天内回复
-
AI Chat Web template: scaffolded Identity pages are inaccessible because App.razor applies an interactive render mode unconditionally可能已有人在做 @valkiara 于 20 天前认领。 未关闭area-ai-templates untriaged
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/extensions#7889 · 1 条评论 ·
维护者通常 1 天内回复
查看 dotnet/extensions 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
-
area/backend type/bug
难度 2/5 1-3 小时 新手友好度 72/100
umbraco/Umbraco-CMS#24668 · 1 条评论 ·
维护者通常 1 天内回复
-
Pri3
难度 2/5 1-3 小时 新手友好度 72/100
MicrosoftDocs/windows-dev-docs#6205 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复