Skip to content

[installer] Replace Polly with a small retry loop - #13452

Merged
simonrozsival merged 2 commits into
mainfrom
simonrozsival-installer-polly-retry-evaluation
Nov 10, 2026
Merged

simonrozsival merged 2 commits into
mainfrom
simonrozsival-installer-polly-retry-evaluation

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Context: f94d880
Context: #12988

Xamarin.Installer.AndroidSDK.Manager.Helper.CheckIfNetworkIsAvailableAsync() was the only in-tree consumer of Polly. Constructing a general-purpose policy for this check adds an assembly and allocation overhead. Replace it with a private retry loop and remove the Polly package references and version property.

The check still makes at most four attempts for TimeoutException or TaskCanceledException, including derived exceptions, with a one-second delay and the same warning on each retry. Terminal timeouts and cancellations return false. Unlike Polly's ExecuteAndCaptureAsync, unexpected exceptions escaping the existing network check or retry logging now propagate instead of being silently converted to false.

Compatibility: This removes the public nested Helper.ResiliencyPolicies type and its AsyncRetryIfTimeout() method. There are no in-repository callers, but external users of that API will experience a source and binary break. #12988 touches the same installer project files but is not a prerequisite.

Measurements: On macOS arm64, an in-process BenchmarkDotNet comparison of the baseline and the initial candidate measured a completed delegate at 300.4 ns / 1.08 KB versus 7.292 ns / 0 B. A separate local HTTP first-call comparison, with the HTTP stack warmed and 25 alternating fresh-process pairs, had medians of 9.394 ms / 60,544 B versus 6.390 ms / 47,280 B. These measurements predate the final catch narrowing and do not establish an end-to-end startup improvement; no in-tree call sites for the network check were found.

Validation: All commands ran under the shared validation lock.

  • dotnet build src/Xamarin.Installer.Build.Tasks/Xamarin.Installer.Build.Tasks.csproj -c Release -nologo -v:q — passed with 10 existing SourceLink/Git warnings.
  • dotnet "$v/bin/$v/Harness.dll" equiv "$m" — passed with the session-local harness for both baseline and candidate: HTTP 200, HTTP 500, refused connection, two timeouts followed by success, and retry exhaustion had matching results, requests, and warnings. An injected logger failure was intentionally converted to false by the baseline and propagated by the candidate.

No repository tests were added; the comparison harness is session-local. AndroidDependenciesTests.InstallAndroidDependenciesTest was not run: it does not call this network-check method and downloads an SDK/JDK.

simonrozsival and others added 2 commits November 10, 2026 04:11
CheckIfNetworkIsAvailableAsync was the only Polly consumer. Replace the
WaitAndRetryAsync policy with a private loop that keeps the same retry
conditions (TimeoutException/TaskCanceledException incl. subclasses),
3 retries with a fixed 1s delay, the same warning message, ConfigureAwait
(false) semantics, and capture-all failure -> false.

Remove the Polly package reference from Xamarin.Installer.AndroidSDK,
Xamarin.Installer.Build.Tasks and Xamarin.Android.Build.Tests, and the
PollyVersion property. Removes the public Helper.ResiliencyPolicies type,
which had no in-repo callers.

Co-authored-by: Copilot App <[email protected]>
Catch only terminal TimeoutException and TaskCanceledException when the network retry budget is exhausted. Unlike Polly ExecuteAndCaptureAsync, unexpected errors escaping the network check or retry logging now fault the returned task instead of silently becoming false. The underlying network check still logs and handles its existing failure cases.

Rebuilt installer tasks in Release and compared the production Helper against the main-baseline binary: HTTP 200, HTTP 500, refused connection, two timeouts then success, and retry exhaustion retain identical results, requests and warnings. An injected logger failure returns false on main and propagates on the candidate as intended. All checks ran under the shared validation lock; artifacts are in session files/revise-retry.log.

Compatibility caveat remains: the earlier removal of public Helper.ResiliencyPolicies is source/binary breaking for any external consumers.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The replacement retry loop lacks checked-in tests for recovery, exhaustion, derived timeout/cancellation exceptions, and retry-logger failures, leaving these behaviors unprotected against CI regressions.

1 open issue
What changed in this PR

Replaces the installer’s only Polly usage with a private retry loop, reducing dependency and policy-allocation overhead without depending on #12988.

Changes:

  • Preserves up to four timeout/cancellation attempts, one-second retry delays, and retry warnings.
  • Allows unexpected exceptions to propagate and removes the public Helper.ResiliencyPolicies API—an acknowledged compatibility break.
  • Removes Polly package references and its shared version property.
File Description
src/​Xamarin.Installer.Build.Tasks/​Xamarin.Installer.Build.Tasks.csproj Removes the Polly package reference.
src/​Xamarin.Installer.AndroidSDK/​Xamarin.Installer.AndroidSDK/​Common/​Helper.cs Replaces the Polly policy with a private retry loop and narrows exception handling.
src/​Xamarin.Installer.AndroidSDK/​Xamarin.Installer.AndroidSDK.csproj Removes the Polly dependency and asset configuration.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Xamarin.Android.Build.Tests.csproj Removes the test project’s Polly reference.
Directory.Build.props Removes the unused Polly version property.

Review effort: Balanced

for (int attempt = 0; ; attempt++) {
try {
return await action ().ConfigureAwait (false);
} catch (Exception exception) when (attempt < retryCount && (exception is TimeoutException || exception is TaskCanceledException)) {
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 10, 2026
@simonrozsival
simonrozsival enabled auto-merge (squash) November 10, 2026 17:16
@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto review

@simonrozsival
simonrozsival merged commit aeafefd into main Nov 10, 2026
41 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-installer-polly-retry-evaluation branch November 10, 2026 18:40
simonrozsival added a commit that referenced this pull request Nov 10, 2026
Context: #13452

The rebase conflict resolution restored Polly package references even though main had already replaced the installer retry policy. Remove those references and the unused version property; the retry implementation remains unchanged.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants