Repository navigation
Description
Bug summary
When the macOS backend is used to draw a figure in Ventura (I am on 13.4.1), it crashes with an XPC misuse error when it is run from a non-root and non-logged-in user (from what I can tell).
...
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000181f5db40
Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [35989]
Application Specific Signatures:
API Misuse
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libxpc.dylib 0x181f5db40 _xpc_api_misuse + 92
1 libxpc.dylib 0x181f3fb2c xpc_connection_set_target_uid + 216
2 WindowManagement 0x208de9cf0 -[WMClientWindowManager _createXPCConnection] + 968
3 WindowManagement 0x208dea630 -[WMClientWindowManager _xpcConnection] + 172
4 WindowManagement 0x208de83f0 -[WMClientWindowManager stages] + 84
5 AppKit 0x185e5e568 __54-[NSWMWindowCoordinator initializeStageFramesIfNeeded]_block_invoke + 32
6 libdispatch.dylib 0x18204c400 _dispatch_client_callout + 20
7 libdispatch.dylib 0x18204dc40 _dispatch_once_callout + 32
8 AppKit 0x185e5e514 -[NSWMWindowCoordinator initializeStageFramesIfNeeded] + 304
9 AppKit 0x18550b278 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 660
10 AppKit 0x18550ac50 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 684
11 AppKit 0x18550a998 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
12 ??? 0x118de0980 -[Window initWithContentRect:styleMask:backing:defer:withManager:] + 68
13 ??? 0x118de3f74 FigureManager_init + 240
14 ??? 0x101106744 wrap_init + 20
15 ??? 0x1010a735c wrapperdescr_call + 392
16 ??? 0x10109e400 _PyObject_MakeTpCall + 360
...
Code for reproduction
N/AActual outcome
N/A
Expected outcome
N/A
Additional information
The most common place I have seen this is when a module consuming matplotlib draws figures in its tests without specifying a backend. When that module is built by the nix package manager, the build is performed by a non-root, non-logged-in user, triggering this crash.
I do not think there is anything actionable here but wanted to open an issue to help anyone else who runs into this. Perhaps detection is possible during backend selection, but it's not entirely obvious to me how to do it robustly. If the team agrees, we can close this issue.
Operating system
macOS 13.4.1
Matplotlib Version
3.7.1
Matplotlib Backend
macosx
Python version
3.10.11
Jupyter version
No response
Installation
None
Activity
jklymak commentedon Jul 12, 2023
I'm not sure I completely understand but I can imagine it doesn't make sense to use any gui backend if the user is not logged in and hence has no display.
tacaswell commentedon Jul 12, 2023
The quick fix is for nix to set the
MPLBACKEND=aggenv for those packages when running tests.For linux we have a helper to detect if we have a usable display and if not, the auto-backend selection falls back to a non-interactive backend. I suspect that something similar is possible for OSX to detect if we have a usable GUI display.
I tried to reproduce this by sshing into a mac without being logged in, but that failed in other ways (blocking
show()blocked...forever and there was no window even after I logged in).I think this is a good first issue because it will be adding a private helper function + one or two calls to it in the backend selection logic and/or the backend start up code.
Tasks:
I would say this is medium difficulty as it is possible that there is a call in the OSX SDK that just answers this question, but might require research to find it. You will also have to understand the auto backend selection logic.
github-actions commentedon Jul 12, 2023
Good first issue - notes for new contributors
This issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide.
We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR.
If something is unclear, please reach out on any of our communication channels.
tacaswell commentedon Jul 12, 2023
I labeled this as 3.9 to keep it out of our 3.8 wrap up workstream for now. If this ends up being simple no problem in backporting it to 3.8.x .
tjni commentedon Jul 12, 2023
Thank you for responding! I cobbled together these reproduction steps on my macOS 13.4.1 M1 machine:
me.test.py:python test.pydoes not crash.someuser:me's home directory:someuser(password ispassword):python test.pycrashes:tacaswell commentedon Jul 12, 2023
Thank you for the reproduction examples but that is not something we can put in the test suite!
QuLogic commentedon Jan 20, 2024
I wonder if we look at the list of screens, it would be empty in this case?