Skip to content

Add opt-in HTTP client recovery for transient network errors - #16662

Draft
Julio César Rocha (JunielKatarn) wants to merge 5 commits into
microsoft:mainfrom
jurocha-ms:OfficeDev/office-js/4972-httpproxy
Draft

Julio César Rocha (JunielKatarn) wants to merge 5 commits into
microsoft:mainfrom
jurocha-ms:OfficeDev/office-js/4972-httpproxy

Conversation

@JunielKatarn

@JunielKatarn Julio César Rocha (JunielKatarn) commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

Classic Outlook launch-event add-ins (OfficeDev/office-js#4972) report fetch() calls that stall or fail with WinINet transport errors (e.g. 0x80072efd, 0x80072ee7, 0x80072ee2) after sleep/resume on machines using a loopback HTTP proxy with PAC rules. Requests only recover minutes later or after restarting Outlook.

WinRTHttpResource keeps a single HttpClient/filter chain for the lifetime of the React instance, so it can keep reusing stale connection/proxy state after a network transition. This change adds an opt-in, bounded recovery path that retries once through a freshly constructed client.

Resolves OfficeDev/office-js#4972

What

Adds the boolean RuntimeOption Http.RetryOnTransientNetworkError (default false; existing behavior is unchanged unless enabled).

When enabled, WinRTHttpResource retries at most once, using a newly constructed filter and HttpClient chain, when:

  • The method is GET or HEAD (case-insensitive; the transmitted method spelling is preserved), and
  • The failure is a selected transient WinINet transport error (timeout, name resolution, cannot connect, connection aborted/reset, disconnected, proxy unreachable).

It does not retry:

  • POST or other potentially non-idempotent methods.
  • RNW's own request-timeout path.
  • Certificate validation failures.
  • HTTP error responses (e.g. 503).
  • Cancelled/aborted requests.
  • ERROR_INTERNET_FORCE_RETRY.

Other details:

  • Concurrent failures from the same client generation share a single replacement client.
  • Cancellation and the original wall-clock timeout budget apply across both attempts.
  • TestWebSite gains a fail-once endpoint (GET /officedev/office-js/issues/4972/{id}) that aborts the first connection before response headers and returns 200 on the second request.

Reviewers: please pay particular attention to the selected retryable HRESULT set, and whether the RuntimeOption name/activation mechanism is appropriate for the intended host rollout.

Screenshots

N/A

Testing

Added deterministic unit tests (vnext/Desktop.UnitTests/WinRTHttpResourceUnitTest.cpp) using an injected client factory to count client generations. They cover:

  • Default-off compatibility.
  • Fresh-client retry for GET, HEAD, and mixed-case GET.
  • WinINet timeout retry.
  • One-retry limit.
  • POST, certificate, HTTP-response, and explicit-timeout safety.
  • Remaining timeout budget.
  • Abort during client replacement.
  • Concurrent failures sharing one replacement client.

Added integration test OfficeDev_OfficeJS_4972_RetriesGetWithFreshClientAfterConnectionFailure (vnext/Desktop.IntegrationTests/HttpResourceIntegrationTests.cpp), which drives a real Kestrel connection reset through the full WinRT transport and verifies recovery.

Ran locally (x64 Debug, after rebasing on main):

  • msbuild vnext\ReactWindows-Desktop.sln /m /r: succeeded.
  • vstest.console.exe vnext\target\x64\Debug\React.Windows.Desktop.UnitTests\React.Windows.Desktop.UnitTests.dll --InIsolation --Platform:x64: 123 total, 120 passed, 3 skipped (pre-existing CORS skips), 0 failed.
  • .\vnext\Scripts\IntegrationTests.ps1 -NoServers -Include HttpResourceIntegrationTest (with TestWebSite running): 13 passed, 0 failed.

Known gaps: the tests do not reproduce enterprise PAC/loopback proxy software or real sleep/resume transitions; these are better suited to manual/lab validation.

Changelog

Should this change be included in the release notes: yes

Add opt-in Http.RetryOnTransientNetworkError RuntimeOption that retries idempotent (GET/HEAD) requests once through a fresh HTTP client after transient network transport failures.

Microsoft Reviewers: Open in CodeFlow

Add fail-once integration coverage for OfficeDev/office-js#4972 and unit specifications for fresh-client retry policy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49ef9095-9eea-4a32-a660-c04ea1965495
Gate fresh-client retries for transient GET and HEAD failures behind Http.RetryOnTransientNetworkError while preserving cancellation, timeout, and concurrency behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49ef9095-9eea-4a32-a660-c04ea1965495
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 88a87e75-1858-477f-be48-24484ba8eb86
</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
$(VCInstallDir)UnitTest\include;
"$(IntDir)\..\React.Windows.Desktop\Generated Files";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(nit) Is there a better macro to resolve this path?

#include <CppUnitTest.h>

#include <CppRuntimeOptions.h>
#include <Networking\WinRTHttpResource.h>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TODO: Forward-slash

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 88a87e75-1858-477f-be48-24484ba8eb86

This branch has not been deployed

No deployments
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.

[TypeError: Network request failed] occurs randomly

1 participant