Skip to content

fix(v3): cancel aborted Windows asset requests - #6100

Merged
leaanthony merged 1 commit into
masterfrom
fix/windows-request-cancellation-5963
Sep 9, 2026
Merged

leaanthony merged 1 commit into
masterfrom
fix/windows-request-cancellation-5963

Conversation

@leaanthony

@leaanthony leaanthony commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Description

Aborting an asset request in a Windows WebView currently leaves its Go handler running. This change connects WebView2 request identities to handler contexts so fetch/XHR aborts, worker termination, navigation, and window/application shutdown can cancel the corresponding work. Concurrent requests to the same URL remain independent.

Use WebView2's in-process DevTools API to associate intercepted requests with cancellation events, including events from worker sessions. Preserve local keepalive handlers across page/worker teardown while still honouring explicit aborts. Bound keepalive registrations and clean them up when delivery or handlers finish. No remote debugging port or new dependency is required.

Also forward native contexts through webViewAssetRequest: the shared wrapper currently drops the contexts supplied by the Apple implementation in #5969. A native macOS comparison reproduced the problem and verified the forwarding fix.

Addresses the v3 Windows portion of #5963 and completes shared context forwarding for the Apple implementation. This PR does not implement v2 or Linux native cancellation, so it should not automatically close the broader issue.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • WEP (proposal only; no implementation)
  • Breaking change
  • This change requires a documentation update

How Has This Been Tested?

  • Windows
  • macOS
  • Linux native desktop

On win-node1, all 66 production scenarios passed: 55 expected cancellations and 11 completion controls. Coverage includes fetch/XHR, uploads and headers, internal/external redirects, identical URLs, iframes, workers, page/window/application teardown, keepalive behavior, 40 concurrent aborts, CORS preflight isolation, and response URLs. The earlier debug run also passed its 64 scenarios.

Additional validation:

  • Full Windows and macOS application test suites passed.
  • Windows request tracker/wrapper tests and asset-server race tests passed.
  • Six JavaScript helper tests passed.
  • Windows x64, x86, and ARM64 builds passed; only x64 was executed natively.
  • Linux server-mode compilation passed; Linux desktop and iOS were not run.
  • CodeRabbit review completed. Its finding about unbounded keepalive registration was fixed and covered by a regression test.

Reproduce from v3:

go test ./pkg/application
go test -race ./internal/assetserver/...
node --test pkg/application/request_keepalive_windows_test.mjs
go build -tags production -o cancellation-probe.exe ./pkg/application/testdata/request-cancellation

Run the probe in an interactive Windows session. It writes JSON results and exits nonzero on failure. See v3/pkg/application/testdata/request-cancellation/README.md for details. Native application test binaries must run from the application source directory because some existing tests inspect source files.

Test Configuration

Recorded from the native probe rather than wails doctor: win-node1, Windows 11 Pro 25H2, build 26200, x64; WebView2 152.0.4191.66; Go 1.26.2. macOS tests ran on the local Apple Silicon host. The native macOS comparison showed aborted fetch/XHR handlers reaching a four-second timeout on master and cancelling at approximately 704 ms with context forwarding; normal requests completed in both runs.

Checklist

  • (v2 only) Updated the v2 changelog — not applicable
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented hard-to-understand areas
  • I have made corresponding documentation changes
  • My changes generate no new warnings — macOS linking emits existing SDK/deployment-target warnings
  • I have added tests that prove the fix is effective
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows request cancellation for fetch, XHR, redirects, workers, navigation, and window closure.
    • Keepalive requests now complete or cancel more reliably during navigation and application shutdown.
    • Preserved native request cancellation contexts on Apple platforms.
    • Improved handling of request bodies, headers, redirects, and external navigation during cancellation.
  • Developer Features

    • Added Windows WebView2 DevTools Protocol support for invoking commands and receiving events.

Connect in-process WebView2 request identities to handler contexts, including worker aborts and lifecycle cleanup. Preserve keepalive work across page and worker teardown, bound its registrations, and forward native contexts through the shared application wrapper.

Validate with 66 native Windows production scenarios, Windows and macOS application tests, asset-server race tests, and Windows x64/x86/ARM64 builds. Refs #5963 and #5969.
Copilot AI lite review requested due to automatic review settings September 9, 2026 21:51
@github-actions github-actions Bot added Bug Something isn't working v3 labels Sep 9, 2026
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5c066df1-3d9f-4fa8-ba5d-322c614ab190

📥 Commits

Reviewing files that changed from the base of the PR and between 7cfcdbc and d074e4e.

📒 Files selected for processing (14)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/internal/assetserver/webview/request_tracker.go
  • v3/internal/assetserver/webview/request_tracker_test.go
  • v3/internal/webview2/pkg/edge/devtools.go
  • v3/pkg/application/application.go
  • v3/pkg/application/asset_request_context_test.go
  • v3/pkg/application/request_cancellation_windows.go
  • v3/pkg/application/request_cancellation_windows_test.go
  • v3/pkg/application/request_keepalive_windows.js
  • v3/pkg/application/request_keepalive_windows_test.mjs
  • v3/pkg/application/testdata/request-cancellation/README.md
  • v3/pkg/application/testdata/request-cancellation/main.go
  • v3/pkg/application/testdata/request-cancellation/page.html
  • v3/pkg/application/webview_window_windows.go

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


Walkthrough

Adds Windows asset request cancellation through WebView2 DevTools Protocol, token-based request tracking, worker and keepalive lifecycle handling, and teardown integration. The application wrapper now forwards native request contexts. Unit, Node.js, and Windows regression tests cover the new behavior.

Changes

Asset request cancellation

Layer / File(s) Summary
Request tracking and ownership
v3/internal/assetserver/webview/request_tracker.go, v3/internal/assetserver/webview/request_tracker_test.go
Adds token-based request tracking with cancellation, keepalive limits, context ownership transfer, cleanup, and concurrency tests.
WebView2 DevTools bridge
v3/internal/webview2/pkg/edge/devtools.go
Adds CDP method calls, session-scoped calls, event subscriptions, COM callbacks, and HRESULT handling for Windows WebView2.
Windows cancellation flow
v3/pkg/application/request_cancellation_windows.go, v3/pkg/application/request_keepalive_windows.js, v3/pkg/application/webview_window_windows.go, v3/pkg/application/*_test.*
Intercepts asset requests, propagates tracking tokens, handles workers and keepalive requests, and closes subscriptions and tracked state with the WebView.
Native context forwarding and regression coverage
v3/pkg/application/application.go, v3/pkg/application/asset_request_context_test.go, v3/pkg/application/testdata/request-cancellation/*, v3/UNRELEASED_CHANGELOG.md
Forwards native request contexts and adds application tests plus a Windows regression probe for cancellation scenarios.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Merge Risk: ⚪ Minimal · up to d074e

No actionable merge-blocking risk remains after normal checks.

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant Chromium
  participant Cancellation as windowsRequestCancellation
  participant Tracker as RequestTracker
  participant Handler as Asset handler
  Browser->>Cancellation: Start or abort asset request
  Cancellation->>Chromium: Intercept request or receive network event
  Cancellation->>Tracker: Register, cancel, or wrap request token
  Tracker->>Handler: Provide request context
  Handler-->>Tracker: Complete and close request
  Tracker-->>Cancellation: Release tracked request
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 11 files. (3 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: cancellation of aborted Windows asset requests.
Description check ✅ Passed The description is complete and relevant. It explains the Windows and Apple context-cancellation changes, references issues #5963 and #5969, documents testing and configuration, and records checklist …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 11 files. (3 skipped: 3 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/windows-request-cancellation-5963

Warning

Some tools did not complete. Review the errors below.

🔧 golangci-lint (2.13.2)

level=error msg="[linters_context] typechecking error: build constraints exclude all Go files in /v3/pkg/application/testdata/request-cancellation"
level=error msg="[linters_context] typechecking error: build constraints exclude all Go files in /v3/internal/webview2/pkg/edge"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit hops where request trails cross
Tokens guide the paths and measure loss
Workers pause, then safely flee
Keepalive streams stay wild and free
Contexts carry cancellation near
Windows now knows when to clear

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added Documentation Improvements or additions to documentation Windows labels Sep 9, 2026

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.

🟢 Approval recommended

The changes are cohesive, well-tested (unit + JS + native probe), and the cancellation/context-forwarding logic appears correct with appropriate cleanup and bounds.

Pull request overview

This PR fixes a long-standing v3 Windows custom-scheme limitation where aborting a fetch/XHR (or losing a page/worker) did not cancel the Go-side request context, by wiring WebView2 DevTools request identities to per-request cancellation contexts. It also corrects webViewAssetRequest to preserve native cancellation contexts provided by platform implementations (notably Apple).

Changes:

  • Add Windows WebView2 DevTools-based request tracking to cancel Go handlers on abort/teardown while keeping concurrent same-URL requests independent.
  • Preserve keepalive fetch handlers across page/worker teardown, while still honoring explicit abort, with bounded registration and cleanup.
  • Forward native request contexts through the shared webViewAssetRequest wrapper and add regression tests.
File summaries
File Description
v3/UNRELEASED_CHANGELOG.md Adds release note for Windows cancellation + shared context forwarding.
v3/pkg/application/webview_window_windows.go Installs request cancellation tracker and ensures shutdown closes it.
v3/pkg/application/request_cancellation_windows.go Implements DevTools session wiring, request identity mapping, and cancellation/keepalive lifecycle.
v3/pkg/application/request_cancellation_windows_test.go Adds focused unit tests for worker/session identity and shutdown/keepalive behaviors.
v3/internal/webview2/pkg/edge/devtools.go Adds in-process DevTools protocol call + event subscription support for WebView2.
v3/internal/assetserver/webview/request_tracker.go Adds concurrency-safe request token tracker mapping browser IDs to Go contexts.
v3/internal/assetserver/webview/request_tracker_test.go Adds tracker regression tests (independence, redirects, abort timing, keepalive bounds).
v3/pkg/application/request_keepalive_windows.js Injected helper to mark local keepalive requests and report explicit abort vs delivery failure.
v3/pkg/application/request_keepalive_windows_test.mjs Node tests for the keepalive helper’s behavior and invariants.
v3/pkg/application/application.go Forwards native request contexts through the wrapper (fixes dropped cancellation).
v3/pkg/application/asset_request_context_test.go Regression tests validating native context preservation and fallback behavior.
v3/pkg/application/testdata/request-cancellation/* Native Windows probe app + assets to exercise full cancellation matrix end-to-end.
Review details
  • Files reviewed: 14/14 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@leaanthony
leaanthony merged commit aaa98e6 into master Sep 9, 2026
61 checks passed
@leaanthony
leaanthony deleted the fix/windows-request-cancellation-5963 branch September 9, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation v3 Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants