High CPU load of diagnosticd process while running React Native app on iOS simulator

Viewed 4068

I have been developing with React Native for some years now but the following behaviour only started recently. After running any React Native app on the iOS simulator (either directly from Xcode or via react-native run-ios) the diagnosticd process slowly increases CPU usage to 150% after a couple of minutes. My laptop becomes unusable because the process is also eating up all file handles of the OS. Googling around only points to excessive logging, but either I'm not looking in the right location or no huge amounts of logging is taking place.

Closing the app by pressing the Home button in the simulator immediately stops the high cpu load.

Is anybody also experiencing this? How can I find out what is causing this?

MacOS Catalina version 10.15.3, Xcode version 11.4, React version 16.9.0, React Native version 0.61.5, Simulator iPhone 11 (iOS 13.4)

5 Answers

I think I found the solution. Xcode was logging a lot of lines containing: xcode nw_connection_get_connected_socket Client called nw_connection_get_connected_socket on unconnected nw_connection. This started after some update of Xcode a couple of months ago. Disabling the logging has stopped the diagnosticd process from eating up all OS resources. I followed these instructions: Hide strange unwanted Xcode logs

Basically comes down to adding an environment variable OS_ACTIVITY_MODE with value disable to the Scheme (Run).

What the real reason for the logging is I still don't know. It looks like some sort of polling from React Native.

It's more of a workaround than a solution, but it seems that resetting the simulator to factory default temporary fix this problem (at least on my case).

It looks like diagnosticd is processing some files which may be located on the simulator internal memory, so it may takes more and more cpu as the files are growing over time ?

Anyway try to go to the simulator menu : Hardware -> Erase All Content and Settings Then close the simulator and start it again from XCode in order to copy your app on it.

Finally found the solution! I was always wondering why the default url in AppDelegate.m did not work. So I started focusing on that. It turns out that my huge adblocking hosts file was the cause of this. Restoring the original /etc/hosts file solved both problems!

One more thing you can try, this is a very drastic measure and only do this at your own risk,

first try this,

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.diagnosticd.plist

and if you get a message about system protection (SIP),

you can try turning off SIP, then running that command again,

That will pretty much guarantee diagnosticd never run's again... no idea about the implications of that though...

read more about those two things here,

https://makandracards.com/dev/16439-disable-daemons-services-in-mac-os-x

https://www.imore.com/how-turn-system-integrity-protection-macos

*disclaimer, this is probably not the safest solution messing with SIP, but I did it on my old 2015 i5 macbook because I was getting desperate, and literally couldn't do any work on simulator with the diagnosticd bug.

So far everything seems happy...

Related