Subject: bug#38618: 27.0.50; Mach port leak on macOS Catalina causing crash

From: Alan Third <[email-masked]>
Date: Sun, 15 Dec 2019 14:48:27 +0000

On Sun, Dec 15, 2019 at 02:35:10PM +1300, Phillip Hutchings wrote:
> 
> 
> On macOS Catalina (all versions up to and including 10.15.2), after
> opening a file stored on an iCloud Drive folder Emacs leaks Mach ports
> eventually resulting in an Emacs crash during a random syscall.
> 
> Reproduction:
> * Using Emacs for MacOS X (currently using Nightly build, but also on
> the 26.3 release from 2019-09-02
> * Open a file stored in an iCloud Drive folder, eg Documents when using
> default settings
> * Modify the file, no need to save it, only modify the contents
> * Emacs will leak Mach ports on every edit.
> 
> This does not happen on non-iCloud Drive files, the port count observed 
> in Activity Monitor does not change for these files.
> 
> So far I've removed all customisations, then tried disabling file
> backups and auto saves, and pretty much anything I can think of that
> accesses files. So far I haven't managed to find a cause. 

This sounds strange. I’m not on Catalina, nor do I use icloud, so I
can’t debug this locally.

Can you try enabling NSTRACE (uncomment line 55 in nstrace.h) and then
compare the output when editing a file that doesn’t leak vs one that
does? It might be worth enabling NSTRACE_GROUP_EVENTS too, but it
results in a ton of output, so perhaps try without it first.

Oh, and can you try testing with ‘emacs -nw’, just in case it’s not
related to the window system code.
-- 
Alan Third