Skip to content

Log background cache refresh failures in LocationResolver#4550

Merged
pepone merged 2 commits intoicerpc:mainfrom
pepone:fix/4428-background-refresh-logging
Apr 27, 2026
Merged

Log background cache refresh failures in LocationResolver#4550
pepone merged 2 commits intoicerpc:mainfrom
pepone:fix/4428-background-refresh-logging

Conversation

@pepone
Copy link
Copy Markdown
Member

@pepone pepone commented Apr 24, 2026

Fixes #4428

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 24, 2026 09:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #4428 by ensuring failures from fire-and-forget background cache refreshes in the locator location resolution flow are observed and logged, instead of silently becoming unobserved task exceptions.

Changes:

  • Add a background refresh helper in LocationResolver that awaits refresh work and logs failures.
  • Thread an ILogger into the cached LocationResolver implementation and introduce a new log event ID for background refresh failures.
  • Update locator tests and composition root to pass a logger into LocationResolver.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/IceRpc.Locator.Tests/LocationResolverTests.cs Updates LocationResolver construction to pass NullLogger.Instance after constructor signature change.
src/IceRpc.Locator/LocatorInterceptor.cs Passes logger into LocationResolver from the locator composition root.
src/IceRpc.Locator/LocationEventId.cs Adds BackgroundRefreshFailed event id for the new log message.
src/IceRpc.Locator/Internal/LocationResolver.cs Replaces fire-and-forget refresh with RefreshInBackgroundAsync that catches and logs refresh exceptions.

Comment on lines +169 to +178
private async Task RefreshInBackgroundAsync(Location location)
{
try
{
_ = await _serverAddressFinder.FindAsync(location, cancellationToken: default).ConfigureAwait(false);
}
catch (Exception exception)
{
_logger.LogBackgroundRefreshFailed(location.Kind, location, exception);
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new background-refresh error logging path (catch in RefreshInBackgroundAsync) isn’t covered by tests. Please add a unit test that forces IServerAddressFinder.FindAsync to throw during a background refresh (expired cache entry + background enabled) and asserts a log entry is emitted with EventId=BackgroundRefreshFailed and the exception attached (e.g., using TestLoggerFactory from IceRpc.Tests.Common).

Copilot uses AI. Check for mistakes.
return (serviceAddress, serviceAddress is not null && !resolved);
}

private async Task RefreshInBackgroundAsync(Location location)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Minor) I would use a local function. That's the pattern we typically use.

Matches the pattern used elsewhere in the repo (e.g. ClientConnection's
PerformDisposeAsync/PerformShutdownAsync) — the helper is only invoked
from inside PerformResolveAsync and captures the enclosing 'location'
parameter, so a local function expresses that scope more directly than
a private instance method.
@pepone pepone merged commit 0d08ac5 into icerpc:main Apr 27, 2026
7 of 10 checks passed
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.

[Audit-Low] background cache refresh faults are fire-and-forget and b…

4 participants