Repository navigation
fix(v3): cancel aborted Windows asset requests - #6100
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (14)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. WalkthroughAdds 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. ChangesAsset request cancellation
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~60 minutes Merge Risk: ⚪ Minimal · up to 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
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation 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.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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" 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. A rabbit hops where request trails cross Comment |
There was a problem hiding this comment.
🟢 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
webViewAssetRequestwrapper 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.
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
How Has This Been Tested?
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:
Reproduce from
v3: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.mdfor 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
Summary by CodeRabbit
Bug Fixes
Developer Features