beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.48k stars 352 forks source link

PySide apps seg fault on macOS using Python 3.12 #1794

Closed rmartin16 closed 2 weeks ago

rmartin16 commented 1 month ago

Describe the bug

CI for briefcase-macOS-app-template reported a failure for PySide on 3.12 today. While importing shiboken6, the app seg faults.

Found originally in https://github.com/beeware/briefcase-macOS-app-template/pull/55#issuecomment-2106440930.

Trackback on Sonoma x86:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00000000000000a8
Exception Codes:       0x0000000000000001, 0x00000000000000a8

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [17381]

VM Region Info: 0xa8 is not in any region.  Bytes before following region: 4493352792
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      10bd32000-10c07e000    [ 3376K] r-x/r-x SM=COW  /Users/USER/*/pysideauto.app/Contents/MacOS/pysideauto

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   pysideauto                             0x10bdf40a4 PyType_Ready + 4
1   libshiboken6.abi3.6.7.dylib            0x10edc1740 Shiboken::init() + 48
2   libshiboken6.abi3.6.7.dylib            0x10edd4a06 Shiboken::Module::create(char const*, void*) + 70
3   Shiboken.abi3.so                       0x10c8e9d08 PyInit_Shiboken + 56
4   pysideauto                             0x10bee43ee _PyImport_LoadDynamicModuleWithSpec + 590

Steps to reproduce

Using Python 3.12, run briefcase run macos app or briefcase run macos xcode for a PySide6 app. While there is a new 6.7.0 release, the previous release triggers the same seg fault.

Expected behavior

PySide apps run properly.

Screenshots

No response

Environment

Logs

briefcase.2024_05_12-23_38_21.run.log pyside_macos_x86.dump.txt

Additional context

A related issue is Briefcase failed to report the app did not run properly. That issue is being tracked in #1795.

freakboy3742 commented 1 month ago

I've done a little poking around on this; from my initial investigation, it looks like the issue isn't the binary merging or signing. If you reduce the signing to only the app bundle (not suitable for notarisation, but enough to get the app to start), and you remove all the strip/merge behavior from Briefcase (so the binary wheels are used as-is), the same error occurs. If you use the packaged app code and fully signed/merged binaries, but use the system Python to execute them (i.e., set the PYTHONPATH to include the app and app_packages folders, then run python -m testapp), that also works fine.

My current theory is one of two things:

freakboy3742 commented 1 month ago

Tagging @cmaureir after a conversation at PyCon US.

rmartin16 commented 2 weeks ago

I think this has been resolved:

  • [PYSIDE-2676] A crash with Python 3.12 when creating classes from meta classes has been fixed.

I guess we could mark some of these versions as forbidden....but....probably overkill

rmartin16 commented 2 weeks ago

It is interesting, though, that PYSIDE-2676 says they ~could~ couldn't reproduce the error on macOS....

freakboy3742 commented 2 weeks ago

Agreed this appears to be fixed - the most recent builds on the briefcase-macOS-app-template for Pyside6 and Py3.12 show the "successful startup" message.

Since a new project will pick up the most recent release of PySide, and existing projects wouldn't pick up any change that we made, I agree it's probably not worth marking the "bad" releases.