Skip to content

Fix notarization retry logging errors on intermediate attempts - #16669

Merged
ViktorHofer merged 5 commits into
mainfrom
fix/signtool-notarization-retry-errors
Apr 2, 2026
Merged

ViktorHofer merged 5 commits into
mainfrom
fix/signtool-notarization-retry-errors

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

Problem

The notarization retry loop in SignTool.cs calls RunMSBuild up to 5 times. However, RealSignTool.RunMSBuild calls _log.LogError() when MSBuild fails (timeout or non-zero exit code). Since MSBuild's TaskLoggingHelper.LogError() permanently marks the task as failed, intermediate retry failures poison the build even if a later retry succeeds. Additionally, using LogWarning for intermediate failures is unsafe because MSBuildTreatAllWarningsAsErrors can promote warnings to errors.

Fix

Added a bool suppressErrors parameter to the abstract RunMSBuild method. The existing retry loop in SignTool.AuthenticodeSignAndNotarize passes suppressErrors: true for all intermediate attempts and suppressErrors: false only for the final attempt. RealSignTool uses this flag to branch between LogMessage(MessageImportance.High) (safe from warn-as-error) and LogError:

  • Intermediate failures log via LogMessage(MessageImportance.High) — does not poison the build and is safe from warn-as-error promotion
  • Only the final failure logs an error
  • The existing per-attempt log file naming in SignTool is preserved unchanged
  • The signing call site uses the default suppressErrors: false, preserving existing behavior

Changes

  • SignTool.cs - Updated abstract RunMSBuild signature to add bool suppressErrors = false; added suppressErrors: attempt < maxRetries to the notarization RunMSBuild call (loop structure and variable names are otherwise unchanged)
  • RealSignTool.cs - Added bool suppressErrors parameter; branches on suppressErrors to use LogMessage vs LogError
  • ValidationOnlySignTool.cs - Signature update (no behavioral change)
  • FakeSignTool.cs - Signature update (test subclass)

To double check:

steveisok
steveisok previously approved these changes Apr 2, 2026
Add maxAttempts parameter to RunMSBuild. RealSignTool implements retry
logic internally: intermediate failures are logged as warnings instead
of errors (which permanently mark the MSBuild task as failed), and only
the final failure after all retries logs an error.

The notarization call site passes maxAttempts=6. The signing call site
uses the default (1), preserving existing behavior.

Co-authored-by: Copilot <[email protected]>
@ViktorHofer
ViktorHofer force-pushed the fix/signtool-notarization-retry-errors branch from a112c0b to e4acddc Compare April 2, 2026 12:33
@akoeplinger

Copy link
Copy Markdown
Member

Intermediate failures are logged as warnings (don't poison the build)

we don't have warn-as-error in that context right?

akoeplinger
akoeplinger previously approved these changes Apr 2, 2026
ViktorHofer added a commit to dotnet/dotnet that referenced this pull request Apr 2, 2026
Add maxAttempts parameter to RunMSBuild. RealSignTool implements retry
logic internally: intermediate failures are logged as warnings instead
of errors (which permanently mark the MSBuild task as failed), and only
the final failure after all retries logs an error.

The notarization call site passes maxAttempts=6. The signing call site
uses the default (1), preserving existing behavior.

Port of dotnet/arcade#16669

Co-authored-by: Copilot <[email protected]>
LogWarning could be promoted to an error via MSBuildTreatAllWarningsAsErrors,
defeating the retry fix. LogMessage with high importance is safe from
promotion while still being visible in build output.

Co-authored-by: Copilot <[email protected]>
@ViktorHofer

Copy link
Copy Markdown
Member Author

Good catch - MSBuildTreatAllWarningsAsErrors could indeed promote LogWarning to errors. Updated to use LogMessage(MessageImportance.High) instead, which is safe from any warn-as-error promotion while still being visible in build output.

@ViktorHofer
ViktorHofer enabled auto-merge (squash) April 2, 2026 12:54
akoeplinger
akoeplinger previously approved these changes Apr 2, 2026
@ViktorHofer

ViktorHofer commented Apr 2, 2026 •

Copy link
Copy Markdown
Member Author

@copilot investigate and fix the test failures

auto-merge was automatically disabled April 2, 2026 13:38

Head branch was pushed to by a user without write access

Copilot AI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

@copilot investigate and fix the test failures

The failing test was NotarizationRetriesOnFailure — expected 4 attempts (3 failures + 1 success) but got 1.

Root cause: the retry loop was inside RealSignTool.RunMSBuild, but the test uses FakeSignTool, which only made a single attempt.

Fixed in d295a73 by moving the retry loop to SignTool.AuthenticodeSignAndNotarize (base class). All 186 tests now pass.

@ViktorHofer

Copy link
Copy Markdown
Member Author

@copilot minimize the difference that were introduced with this PR. The current state has some changes that are unnecessary from a diff point of view.

Copilot AI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

@copilot minimize the difference that were introduced with this PR. The current state has some changes that are unnecessary from a diff point of view.

Done in cb48af7. Restored SignTool.cs to the original while loop with original variable names (maxRetries, notarizeLogName inside the loop, final _log.LogError) — the only change there is adding suppressErrors: attempt < maxRetries to the RunMSBuild call. The overall diff is now 4 small, focused changes across the 4 files.

@ViktorHofer
ViktorHofer enabled auto-merge (squash) April 2, 2026 14:27
@ViktorHofer
ViktorHofer merged commit ffee086 into main Apr 2, 2026
9 checks passed
@ViktorHofer
ViktorHofer deleted the fix/signtool-notarization-retry-errors branch April 2, 2026 15:19
@radical

radical commented Jul 9, 2026

Copy link
Copy Markdown
Member

/backport to release/10.0

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

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.

6 participants