Skip to content

TraceLayerTest.FollowsTheBackingScaleWithNoSizeChange segfaults intermittently on the macOS runner #445

Open

Description

@zuurbr

In the merge-queue run of #430 (an npm-only dependency update), the macos job's C++ tests failed on one test:

6673 - TraceLayerTest.FollowsTheBackingScaleWithNoSizeChange (SEGFAULT)
***Exception: SegFault  0.26 sec

Scenario and consequence. The crash is in the test run on CI, not reported from a host. A segfault in the trace layer's backing-scale handling could also point at a real fault when the editor window moves to a screen with another scale. Until that's ruled out, it is at least a CI reliability problem: a crash in a required check ejects a pull request from the merge queue, which then has to be queued again (another hour of checks).

Activity

  1. zuurbr commented on Nov 21, 2026

    @zuurbr
    ContributorAuthor

    Cause: a race inside QuartzCore on macOS 15, not the trace layer's code

    Two occurrences. Besides the merge-queue run above, the same test crashed on 2026-11-14 in the macos-glue job (ThreadSanitizer build) of run https://github.com/orizonaudio/Sineless/actions/runs/43653730410, which has a stack:

    ThreadSanitizer: SEGV on unknown address 0x000000000020
    #0 +[CADisplayLink(CADisplayLinkInternal) notifyDisplayChange:]  (QuartzCore+0xe4454)
    #1 invoke_display_change_callback(void*)                         (QuartzCore)
    #2 … libdispatch worker thread
    

    No frame of ours is on the crashing thread.

    What QuartzCore does (disassembled on macOS 27.2):

    • On a display change, QuartzCore runs notifyDisplayChange: on its own queue for each Metal display link. It finds the link in a global list (MetalLinkItem::_list, under _list_lock), then takes the link's lock and reads the link's layer.
    • MetalLinkItem::invalidate() first releases the layer and stores nil (under the link's lock), and only then removes the link from the global list (under _list_lock). A notification that lands between the two steps finds a link whose layer is nil.
    • On macOS 27.2 notifyDisplayChange: checks for a nil layer and skips the link. On the macOS 15 runner the fault matches the missing check: address 0x20, the layer register 0 and the instance-variable offset register 0x20. alpine-gpui reports the same fault on macOS 26.6.2 (fix(macos): invalidate the display link only after the window close dbuddha/alpine-gpui#644), so every supported macOS below 27 (14, 15, 26) lacks the check.

    Why this test. The render server tells a shown layer which display it is on, asynchronously (alpine-gpui traces it to its ImageQueueDidChangeDisplay message; locally a window resize also sends one). This test shows the layer, changes its scale and drawable size about 0.1 s later, then teardown invalidates the link at once, so that message can still be in flight during the invalidation. Both CI runs also had a stalling display, which slows the VM and widens the window. Locally (macOS 27.2) 100 repeats under TSan and 200 separate launches all passed.

    Scenario and consequence for users. On macOS 14 to 26, closing the editor within a few milliseconds of a display-change notification (just after a resize or a move to another screen) could crash the host. The window inside invalidate() is tiny, so it is very unlikely for someone clicking close. On CI it ejected a pull request from the merge queue.

    Fix. The trace layer tests let that message arrive before destroying the layer. The product's close path keeps the race on macOS 14 to 26; whether to change it is a separate decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions