Repository navigation
fix(macos): Keep closed NSWindows alive until AppKit is done - #25201
Conversation
|
Claude finished @MartinZikmund's task in 19s —— View job Review of PR #25201Verdict: fix-first (minor). The change is small and well-reasoned.
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25201/wasm-skia-net9/index.html |
|
The build 238848 found UI Test snapshots differences: Details
|
|
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Verified the UNOWindow.m change (releasedWhenClosed = NO in init, view detach and main-queue removal from the static windows set in windowWillClose) and the new Given_WebView2 test against the PR head and the PR base. The test helpers it uses (WindowHelper.WaitFor, WaitForLoaded, WaitForIdle) exist. WinUI parity does not apply: this is native macOS plumbing.
Findings, most severe first:
-
Medium: the fix changes the object lifetime from "never freed" to "freed one main-queue turn after close". Before this PR
windowskept every closed window alive, so a stale managed handle (MacOSNativeOverlappedPresenter._handle) pointed at a live object. After it, the window is deallocated once the block runs, and any managed handle or AppKit-side reference that still points at it dangles. The PR body states the holder of the stale pointer is not identified. The change therefore moves the free without removing the dangling reference, which does not meet the root-cause bar. Please either identify and clear the holder (for example, invalidate the managed handle on close), or show that nothing retains the window after windowWillClose. -
Low (question): the comment says the removal runs "once AppKit has finished closing the window". A main-queue block is not guaranteed to run after the close call stack unwinds; it can drain inside a nested run loop (event tracking, modal session). Please confirm this is safe in that case, or move the removal to a point that AppKit guarantees has passed (for example, the end of the close sequence).
-
Low:
-deallocnow calls[windows removeObject:self]on an object that the set can no longer hold at that point, so the call is a no-op. Either remove it or leave a comment. -
Low: the regression test has no red/green evidence (the PR body says so). Please run it on the parent commit, or state that the CI crash was nondeterministic so the test cannot be shown to fail. As written it guards the sequence, not the root cause.
Validation: code review (diff plus surrounding code in UNOWindow.m at the PR head). Compile: not built, Objective-C on macOS only. Runtime: none run by me; the CI results in the PR body are the author's and were not verified.
UNOWindow left releasedWhenClosed at its default (YES). Under ARC, AppKit's release on close takes the reference held by the `windows` set, so a closed secondary window was freed mid-close while managed handles and AppKit bookkeeping still pointed at it. Crash dumps of the macOS WebGPU runtime-test lane show a later autorelease-pool drain releasing exactly such a freed window, killing the process (SIGSEGV in objc_release). Turn releasedWhenClosed off, detach the rendering view while the window is still alive, and drop the owning reference on a later turn. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01L4YBGyfjv1uKVn6FUFxSEF
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01L4YBGyfjv1uKVn6FUFxSEF
0df9bcb to
20c3227
Compare
|
Claude finished @ajpinedam's task in 20s —— View job Review of PR #25201Verdict: fix-first (minor)
|
Removing a closed window from `windows` frees it. Queue that from a -close override, after [super close] returns, rather than from windowWillClose:, which runs inside -close. The block then can't run in a run loop nested in -close. Drop -dealloc: the set holds the window, so it is never in the set when deallocated. Claude-Session: https://claude.ai/code/session_01DtUZ4zXC6g5yoXN9Rdt2yx
MacOSNativeOverlappedPresenter kept the window handle it was created with, so a call after the window closed reached the freed NSWindow and crashed the app. Read the handle on each call: closing the window clears it. Claude-Session: https://claude.ai/code/session_01DtUZ4zXC6g5yoXN9Rdt2yx
Master now carries its own fix for the over-released NSWindow (49f4bcf): releasedWhenClosed = NO, and the window leaves `windows` in windowWillClose:, while AppKit keeps it alive until `close` returns. Keep that version. This branch's queued removal and -close override are no longer needed, and -dealloc stays as on master. The rendering view is still detached before the window leaves the set. Claude-Session: https://claude.ai/code/session_01DtUZ4zXC6g5yoXN9Rdt2yx
|
Claude finished @ajpinedam's task in 29s —— View job Review of PR #25201 (re-review after the latest pushes)Verdict: ship, with one optional follow-up.
|
|
Update after the review rounds (the Claude reviews of Oct 10 and today, and the review from morning4coffe-dev). Master now has its own fix for the over-release (49f4bcf, from #25492). I merged master into this branch and kept master's native close code, so this PR's queued removal is gone. On top of master, the PR now adds three things: detaching the rendering view in
Validation on macOS 27.0.1 with Xcode 27.1:
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 241727 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
GitHub Issue: closes #25326, part of #25139
PR Type:
🐞 Bugfix
What changed? 🚀
Fixes the macOS WebGPU lane dying with
Segmentation fault: 11in ~16 of 19 runs, always inGiven_WebView2When_ExecuteScriptAsync*. The 15–60 s silence before it is createdump writing a ~1.9 GB core, not a hang.Split out of #25140 (part of the WebGPU lane stabilization tracked in #25139). The crash-report collection for the macOS lane is in #25197.
objc_releaseduring an autorelease-pool drain, releasing an already-freed object. That object is still referenced by a managedMacOSNativeOverlappedPresenter._handle, so it's a closed secondaryUNOWindow(fromGiven_MultiWindowAccessibility, closed ~10 min earlier). A laterWKWebViewattach triggers the release.UNOWindowkeptreleasedWhenClosedat its defaultYES. Under ARC, AppKit's release on close takes the reference held by the staticwindowsset, so the window is freed mid-close while handles still point at it. Before this change, windows were never removed from that set.releasedWhenClosed = NO; detach the rendering view while the window is alive; drop thewindowsreference on a later main-queue turn.When_Secondary_Windows_Closed_Then_WebView_Still_Works(SkiaMacOS) repeats the sequence. Whether it fails without the fix is unproven, because the CI crash wasn't deterministic.Results (CI builds 238511 and 238573, every WebGPU lane forced on)
In run 238573 the multi-window tests, then all
WebView2ExecuteScriptAsync*tests and the new regression test passed.The Objective-C change was only compiled by CI (it can't be built on Windows). More runs on master after merge will confirm the fix.
PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01TP1JtY64etkfxxGCms44aN