Can you try the attached patch?

It didn’t fix things, but I did find a way to reproduce the problem at will.

If start emacs, and then you run

    open -a /Applications/Emacs.app whatever_file_here

For a file which isn’t open, then the UI becomes unresponsive to input.  Typing C-G seems to unstick it eventually, but there can be very long delays (I timed one at 49 seconds) before it beeps and the UI becomes responsive.  I’ve seen it spontaneously complete too, again after a long time (at least 30 seconds), but usually it does not complete.

If I look at it with lldb, all of the threads are blocked, and thread 1 looks like:

(lldb) bt
* thread #1: tid = 0x4ad0a2, 0x00007fff9f7ebaff CoreFoundation`__CFRunLoopCollectSources0 + 31, stop reason = signal SIGSTOP
  * frame #0: 0x00007fff9f7ebaff CoreFoundation`__CFRunLoopCollectSources0 + 31
    frame #1: 0x00007fff9f7b91f2 CoreFoundation`__CFSetApplyFunction_block_invoke + 18
    frame #2: 0x00007fff9f7a54ba CoreFoundation`CFBasicHashApply + 122
    frame #3: 0x00007fff9f7b9199 CoreFoundation`CFSetApplyFunction + 185
    frame #4: 0x00007fff9f7eb8be CoreFoundation`__CFRunLoopDoSources0 + 110
    frame #5: 0x00007fff9f7eaf76 CoreFoundation`__CFRunLoopRun + 934
    frame #6: 0x00007fff9f7ea974 CoreFoundation`CFRunLoopRunSpecific + 420
    frame #7: 0x00007fff9ed76acc HIToolbox`RunCurrentEventLoopInMode + 240
    frame #8: 0x00007fff9ed76809 HIToolbox`ReceiveNextEventCommon + 184
    frame #9: 0x00007fff9ed76736 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame #10: 0x00007fff9d31cae4 AppKit`_DPSNextEvent + 1120
    frame #11: 0x00007fff9da9721f AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
    frame #12: 0x00000001001b3866 Emacs`ns_select(nfds=4, readfds=0x00007fff5fbfee00, writefds=0x00007fff5fbfed80, exceptfds=0x0000000000000000, timeout=<unavailable>, sigmask=<unavailable>) + 678 at nsterm.m:4130 [opt]
    frame #13: 0x00000001001a04a8 Emacs`really_call_select(arg=0x00007fff5fbfeba0) + 88 at thread.c:520 [opt]
    frame #14: 0x000000010011ec7c Emacs`flush_stack_call_func(func=<unavailable>, arg=<unavailable>) + 44 at alloc.c:5137 [opt]
    frame #15: 0x00000001001a0447 Emacs`thread_select(func=<unavailable>, max_fds=<unavailable>, rfds=<unavailable>, wfds=<unavailable>, efds=<unavailable>, timeout=<unavailable>, sigmask=0x0000000000000000) + 55 at thread.c:543 [opt]
    frame #16: 0x000000010018400e Emacs`wait_reading_process_output(time_limit=<unavailable>, nsecs=<unavailable>, read_kbd=<unavailable>, do_display=<unavailable>, wait_for_cell=0, wait_proc=<unavailable>, just_wait_proc=<unavailable>) + 4142 at process.c:5350 [opt]
    frame #17: 0x0000000100008005 Emacs`sit_for(timeout=<unavailable>, reading=<unavailable>, display_option=1) + 261 at dispnew.c:5763 [opt]
    frame #18: 0x00000001000c3ab7 Emacs`read_char(commandflag=1, map=4431829235, prev_event=0, used_mouse_menu=0x00007fff5fbff7df, end_time=0x0000000000000000) + 5511 at keyboard.c:2725 [opt]
    frame #19: 0x00000001000c062f Emacs`read_key_sequence(keybuf=<unavailable>, bufsize=30, prompt=<unavailable>, dont_downcase_last=<unavailable>, can_return_switch_frame=<unavailable>, fix_current_buffer=<unavailable>, prevent_redisplay=<unavailable>) + 1839 at keyboard.c:9139 [opt]
    frame #20: 0x00000001000bed32 Emacs`command_loop_1 + 1202 at keyboard.c:1373 [opt]
    frame #21: 0x000000010013d347 Emacs`internal_condition_case(bfun=(Emacs`command_loop_1 at keyboard.c:1264), handlers=<unavailable>, hfun=(Emacs`cmd_error at keyboard.c:943)) + 87 at eval.c:1326 [opt]
    frame #22: 0x00000001000cde20 Emacs`command_loop_2(ignore=<unavailable>) + 48 at keyboard.c:1115 [opt]
    frame #23: 0x000000010013cbfe Emacs`internal_catch(tag=<unavailable>, func=(Emacs`command_loop_2 at keyboard.c:1111), arg=0) + 78 at eval.c:1092 [opt]
    frame #24: 0x00000001000bdf7e Emacs`command_loop + 158 at keyboard.c:1094 [opt]
    frame #25: 0x00000001000bde8f Emacs`recursive_edit_1 + 111 at keyboard.c:700 [opt]
    frame #26: 0x00000001000be0c3 Emacs`Frecursive_edit + 227 at keyboard.c:771 [opt]
    frame #27: 0x00000001000bcc9d Emacs`main(argc=0, argv=<unavailable>) + 6157 at emacs.c:1684 [opt]
    frame #28: 0x00007fffb4d43255 libdyld.dylib`start + 1

The other threads didn’t look interesting, but I could be wrong :)

Sometimes when I “continue” in the debugger it unsticks whatever is stuck, though the file I was trying to open never opens.

So far the only problem I’ve seen is
that emacsclient doesn’t return to the shell when it exits.

Yeah, I see that too.

/Bob