Mach Port Leakage - Mojave

An application I am working on (Mostly swift 4.2 with sprinklings of C and C++) appears to be leaking mach ports when run on Mojave and currently has 3,600 open after running for 12 hours. I am just looking at the 'Ports' field in Activity Monitor to see this.


The same binary running on Sierra is using about 500 ports.


The application is quite complex, making extensive use of DispatchQueue() and also has an associated privileged helper.


Unfortunately, I have been unable to create a simple test case that demonstrates the behaviour.


I have done a lot of searching to find out what may be causing the problem and come up with zilch. Is there any debugging tool (i.e. Instruments plugin maybe) that might help to narrow down where the allocation/leakage is coming from. I have seen the results of the tests on google Chrome from a few years back but I'm not keen to start building, installing and debugging kernel extensions to track this problem down.

About BugReporter#4654715


Is there any solution?


I have the same situation when using NSTask execute " ls -l " many times in my Mac application


Activity Monitor -> Memory clearly shows the increasing Mach port count.

About BugReporter#4654715


Is there any solution?


I have the same situation when using NSTask execute " ls -l " many times in my Mac application


Activity Monitor -> Memory clearly shows the increasing Mach port count.

Is there any solution?

“Solution” as in “has the bug been fixed”? Or “solution” as in “workaround”?

On the bug fix front, looking at the bug report (r. 46547156) I don’t see any indication of a fix, and that gels with your experience that you’re able to reproduce the problem.

On the workaround front, you can try dropping down to

posix_spawn
to see if it reproduces there.

Also, are you testing this on 10.14.x? Or 10.15 beta?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks eskimofor response about bug fix front and workaround front
I wish the bug has been fixed, because NSTask is easier to use.

I tested on os 10.14.4Beta.


I replaced NSTask with posix_spawn, Looks like no mach port leakage problem. Still need more testing.

Hi, regarding the Process.run() mach port leak bug (BugReporter #46547156) -- are there any news? resolution? workaround? Was this issue resolved in Catalina? (we're at 10.15.5 already...)

Also - could you kindly share here some of your debugging code (the library and hooks you described) that can help us investigate a similar problem we experience using NSTask?

Thanks!

regarding the Process.run() mach port leak bug (r. 46547156\) -- are there any news?

If I’m reading Radar right, this is fixed in the current macOS 11 beta (r. 50160475) and in 10.15.5 (r. 59969438). I tried reproducing it on my main Mac (running 10.15.5) just now and, as far as I can tell, the patch has stuck.

could you kindly share here some of your debugging code (the library and hooks you described) that can help us investigate a similar problem we experience using NSTask?

Investigating Mach port leaks is really hard in the general case. I’ve already shared my advice on that topic upthread, namely MachPortDump and lsmp.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

Is it the expected behavior that there are no man pages for lsmp … when there is a man page listed here

As a general rule you should expect every tool that’s installed by default and lives somewhere on the default path — and this includes lsmp, which is at /usr/bin/lsmp — to have a man page. I encourage you to file a bug any time that’s not the case.

Please post your bug number, just for the record.

In the meantime, using the man page from Darwin is fine (it’s actually a pleasant surprise to me that it’s there).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Mach Port Leakage - Mojave
 
 
Q