Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS host won't reliably update connected/removed screens and may crash #2523

Open
3 tasks done
Hazer opened this issue May 12, 2024 · 2 comments
Open
3 tasks done
Assignees
Labels
os:macOS OS is macOS

Comments

@Hazer
Copy link
Member

Hazer commented May 12, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your issue described in the documentation?

  • I have read the documentation

Is your issue present in the nightly release?

  • This issue is present in the nightly release

Describe the Bug

On a macOS host, if I start Sunshine with only 1 display connected, and later connect another physical or virtual display, and only then connect with a Client, the host will crash.

This happens because we call video::probe_encoders() on the nvhttp connection threads, which then calls [NSScreen screens] inside av_video. NSScreen has issues with being called on background threads, and while it may correctly work on a conventional NSApplication on some macOS background threads, we are not one. So when we try to get all display names, we get a new display count with all displays, but we still get the old cached NSScreen.screens with less screens, and we index bounds crash.

Expected Behavior

  • NSScreen.screens should be called on main thread;
  • Should always return the updated list of screens;
  • Sunshine should not crash

Additional Context

I'm developing a fix, already have a working prototype, but running things on the main thread, outside of the startup actions, it's currently trick on Sunshine, and my current fix may impact other platforms and current stable behaviors, so while we discuss and evaluate a proper fix and refactor, there's this open issue.

Fixing this issue will predate #2490, and I will use some of the things learned/done there, which will eventually lead to that PR and libdisplay.

Host Operating System

macOS

Operating System Version

Sonoma 14.4.1

Architecture

64 bit

Sunshine commit or version

nightly: b4c12cb

Package

macOS - dmg

GPU Type

n/a

GPU Model

unrelated

GPU Driver/Mesa Version

unrelated

Capture Method (Linux Only)

No response

Config

unrelated

Apps

No response

Relevant log output

[2024:05:12:00:30:43]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
[2024:05:12:00:30:43]: Info: Trying encoder [videotoolbox]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007ff8199a77e6 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff819497e9d objc_exception_throw + 48
	2   CoreFoundation                      0x00007ff8198c2430 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 604
	3   CoreFoundation                      0x00007ff8198c21ba +[NSDictionary dictionaryWithObjects:forKeys:count:] + 49
	4   sunshine-0.23.1.fdb1f623            0x0000000105697020 +[AVVideo displayNames] + 384
	5   sunshine-0.23.1.fdb1f623            0x000000010569839d _ZN5platf7displayENS_10mem_type_eERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERKN5video8config_tE + 493
	6   sunshine-0.23.1.fdb1f623            0x00000001055f2d59 _ZN5video13reset_displayERNSt3__110shared_ptrIN5platf9display_tEEERKNS2_10mem_type_eERKNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS_8config_tE + 73
	7   sunshine-0.23.1.fdb1f623            0x000000010560060e _ZN5video16validate_encoderERNS_9encoder_tEb + 910
	8   sunshine-0.23.1.fdb1f623            0x0000000105603afd _ZN5video14probe_encodersEv + 2973
	9   sunshine-0.23.1.fdb1f623            0x00000001054541b2 _ZN6nvhttp6launchERbNSt3__110shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS6_19basic_stream_socketINS6_2ip3tcpENS6_15any_io_executorEEEEEE8ResponseEEENS2_INSF_7RequestEEE + 2546
	10  sunshine-0.23.1.fdb1f623            0x000000010554bb22 _ZZN6nvhttp5startEvENK3$_7clINSt3__110shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS7_19basic_stream_socketINS7_2ip3tcpENS7_15any_io_executorEEEEEE8ResponseEEENS3_INSG_7RequestEEEE	11  sunshine-0.23.1.fdb1f623            0x000000010554ba7f _ZNSt3__18__invokeB8ue170006IRZN6nvhttp5startEvE3$_7JNS_10shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS8_19basic_stream_socketINS8_2ip3tcpENS8_15any_io_executorEEEEEE8ResponseEEEN	12  sunshine-0.23.1.fdb1f623            0x000000010554ba05 _ZNSt3__128__invoke_void_return_wrapperIvLb1EE6__callB8ue170006IJRZN6nvhttp5startEvE3$_7NS_10shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINSA_19basic_stream_socketINSA_2ip3tcpENSA_1	13  sunshine-0.23.1.fdb1f623            0x000000010554b9cd _ZNSt3__110__function12__alloc_funcIZN6nvhttp5startEvE3$_7NS_9allocatorIS3_EEFvNS_10shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINSA_19basic_stream_socketINSA_2ip3tcpENSA_15any_io_e	14  sunshine-0.23.1.fdb1f623            0x000000010554a9f9 _ZNSt3__110__function6__funcIZN6nvhttp5startEvE3$_7NS_9allocatorIS3_EEFvNS_10shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINSA_19basic_stream_socketINSA_2ip3tcpENSA_15any_io_executor	15  sunshine-0.23.1.fdb1f623            0x00000001054cbde2 _ZNKSt3__110__function12__value_funcIFvNS_10shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS6_19basic_stream_socketINS6_2ip3tcpENS6_15any_io_executorEEEEEE8ResponseEEENS2_INSF_7Reque	16  sunshine-0.23.1.fdb1f623            0x00000001054c070d _ZNKSt3__18functionIFvNS_10shared_ptrIN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS5_19basic_stream_socketINS5_2ip3tcpENS5_15any_io_executorEEEEEE8ResponseEEENS1_INSE_7RequestEEEEEclESG_SI_ 	17  sunshine-0.23.1.fdb1f623            0x00000001054af46b _ZN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS2_19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEEEEE5writeERKNSt3__110shared_ptrINSB_7SessionEEERNSC_8functionIFvNSD_INSB_8ResponseE	18  sunshine-0.23.1.fdb1f623            0x00000001054a248e _ZN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS2_19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEEEEE13find_resourceERKNSt3__110shared_ptrINSB_7SessionEEE + 1166
	19  sunshine-0.23.1.fdb1f623            0x000000010549c000 _ZZN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS2_19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEEEEE4readERKNSt3__110shared_ptrINSB_7SessionEEEENKUlRKNS1_6system10error_codeEmE_cl	20  sunshine-0.23.1.fdb1f623            0x000000010549ad32 _ZN5boost4asio6detail29read_until_delim_string_op_v1INS0_3ssl6streamINS0_19basic_stream_socketINS0_2ip3tcpENS0_15any_io_executorEEEEENS0_19basic_streambuf_refINSt3__19allocatorIcEEEEZN9SimpleWeb1	21  sunshine-0.23.1.fdb1f623            0x000000010549d512 _ZNK5boost4asio3ssl6detail7read_opINS0_17mutable_buffers_1EE12call_handlerINS0_6detail29read_until_delim_string_op_v1INS1_6streamINS0_19basic_stream_socketINS0_2ip3tcpENS0_15any_io_executorEEEEEN	22  sunshine-0.23.1.fdb1f623            0x000000010549d175 _ZN5boost4asio3ssl6detail5io_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_15any_io_executorEEENS2_7read_opINS0_17mutable_buffers_1EEENS0_6detail29read_until_delim_string_op_v1INS1_6streamIS8_EENS	23  sunshine-0.23.1.fdb1f623            0x000000010549e43c _ZN5boost4asio6detail7binder2INS0_3ssl6detail5io_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_15any_io_executorEEENS4_7read_opINS0_17mutable_buffers_1EEENS1_29read_until_delim_string_op_v1INS3_6s	24  sunshine-0.23.1.fdb1f623            0x000000010549e252 _ZN5boost4asio6detail12handler_workINS0_3ssl6detail5io_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_15any_io_executorEEENS4_7read_opINS0_17mutable_buffers_1EEENS1_29read_until_delim_string_op_v1I	25  sunshine-0.23.1.fdb1f623            0x000000010549dfd3 _ZN5boost4asio6detail23reactive_socket_recv_opINS0_17mutable_buffers_1ENS0_3ssl6detail5io_opINS0_19basic_stream_socketINS0_2ip3tcpENS0_15any_io_executorEEENS5_7read_opIS3_EENS1_29read_until_delim	26  sunshine-0.23.1.fdb1f623            0x000000010546f30e _ZN5boost4asio6detail19scheduler_operation8completeEPvRKNS_6system10error_codeEm + 46
	27  sunshine-0.23.1.fdb1f623            0x000000010546ee0a _ZN5boost4asio6detail9scheduler10do_run_oneERNS1_27conditionally_enabled_mutex11scoped_lockERNS1_21scheduler_thread_infoERKNS_6system10error_codeE + 490
	28  sunshine-0.23.1.fdb1f623            0x000000010546ea77 _ZN5boost4asio6detail9scheduler3runERNS_6system10error_codeE + 247
	29  sunshine-0.23.1.fdb1f623            0x000000010555631e _ZN5boost4asio10io_context3runEv + 46
	30  sunshine-0.23.1.fdb1f623            0x0000000105555a36 _ZN9SimpleWeb10ServerBaseIN5boost4asio3ssl6streamINS2_19basic_stream_socketINS2_2ip3tcpENS2_15any_io_executorEEEEEE5startERKNSt3__18functionIFvtEEE + 1750
	31  sunshine-0.23.1.fdb1f623            0x000000010555501e _ZZN6nvhttp5startEvENK4$_10clINS_19SunshineHttpsServerEEEDaPT_ + 94
	32  sunshine-0.23.1.fdb1f623            0x0000000105554f70 _ZNSt3__18__invokeB8ue170006IZN6nvhttp5startEvE4$_10JPNS1_19SunshineHttpsServerEEEEDTclclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOS5_DpOS6_ + 32
	33  sunshine-0.23.1.fdb1f623            0x0000000105554f3e _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZN6nvhttp5startEvE4$_10JPNS6_19SunshineHttpsServerEEJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__	34  sunshine-0.23.1.fdb1f623            0x0000000105554c22 _ZNSt3__114__thread_proxyB8ue170006INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN6nvhttp5startEvE4$_10PNS7_19SunshineHttpsServerEEEEEEPvSC_ + 98
	35  libsystem_pthread.dylib             0x00007ff81985818b _pthread_start + 99
	36  libsystem_pthread.dylib             0x00007ff819853ae3 thread_start + 15
)
libc++abi: terminating due to uncaught exception of type NSException

Process finished with exit code 134 (interrupted by signal 6:SIGABRT)
@Hazer
Copy link
Member Author

Hazer commented May 12, 2024

@ReenigneArcher can you assign this to myself?

@Hazer
Copy link
Member Author

Hazer commented May 12, 2024

As discussed, this can be relevant for the Tray too:

This line disables it on macOS because of main threading issues:

dmikushin/tray#10

So I'll analyze this solution, to be a generic, as possible, way to queue actions to be run on the main thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:macOS OS is macOS
Projects
None yet
Development

No branches or pull requests

2 participants