Reputation: 7146
Running electron 1.4.3, I'm running into a bizarre problem that looks like the event loop is somehow getting stuck. I've set an interval to update every 80 milliseconds, but after about 30 seconds it suddenly updates only once every 10 seconds. Here's some logging from when I was testing it with a once-per-second interval:
2016-10-26T21:30:38.017Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:39.086Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:40.316Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:41.485Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:42.750Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:43.845Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:45.053Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:46.186Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:47.257Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:48.332Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:49.452Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:50.798Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:51.951Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:53.094Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:54.206Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:55.275Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:56.343Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:57.416Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:58.583Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:30:59.704Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:00.772Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:01.841Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:02.977Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:04.048Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:05.118Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:06.289Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:07.381Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:08.506Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:09.583Z [INFO ]-(CommandUtils ) Polling
2016-10-26T21:31:19.964Z [INFO ]-(CommandUtils ) Polling
As you can see from the last handful of lines, the interval suddenly goes from being every second to being once every ten seconds. In my testing, I found that it's quite consistently after about 30 seconds that it goes to updating once every 10 seconds.
However, this issue appears to be system-dependent. We've tested this on a Linux machine and couldn't reproduce the issue. We tested it on a couple other Apple laptops and they, like my Apple laptop, exhibited this strange behavior. Also, the issue appears to depend on where it is run rather than where it is built - building in OSX for Linux then running in Linux did not have any problems, but building in Linux for OSX then running in OSX did have the issue.
I also tried downgrading electron to 1.3.3, but that didn't fix it either.
Update:
I definitely suspect some OSX shenanigans. I previously wasn't using a browser window, but while trying to attach a debugger I ended up opening a browser window attached to the app. As soon as I did that, the throttling did not happen. However, if I put that browser window behind something else (so that it isn't being rendered), the throttling happens about 30 second later.
So how can I prevent OSX from throttling my (currently UI-less) electron app?
Upvotes: 1
Views: 512
Reputation: 7146
As mentioned in Avoid app throttling when Electron is in background, the solution is simple. I just needed to add
electron.powerSaveBlocker.start('prevent-app-suspension');
and OSX won't throttle my app after 30 seconds.
Upvotes: 1