pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.84k stars 838 forks source link

BUG: Multitouch extension spawns rampant processes, rendering computer unusable #3707

Open quarkw opened 9 months ago

quarkw commented 9 months ago

For the past few months, I've noticed that my computer would be unresponsive from wake sometimes. Applications would act very strangely in a broken manner.

I found out it's because sometimes on wake, the Karabiner-MultitouchExtension has a large amount (probably thousands, if not hundreds) of copies. It's hard to get an exact number because it seems like most terminal commands fail since there are too many processes open so that a new process can't be spawned to help determine the number of Karabiner-MultitouchExtension processes, but I can see them in Activity Monitor.

I don't have any screenshots, since I'm unable to take any when my computer is in this state, but I may try to get a picture with my phone next time it happens.

The only solution I've come across to get my computer working again is by restarting it. Trying to quit Karabiner doesn't seem to work.

externvoid commented 8 months ago

The same goes for me. The solution for now is to delete this application all at once with the following command. This happens with Karabiner-Element 14.13.0 and the Karabiner-MultitouchExtension that comes with this.

> killall Karabiner-MultitouchExtension
> sw_vers
ProductName:        macOS
ProductVersion:     14.2.1
BuildVersion:       23C71

My configurations are:

  1. Open at login: off
  2. Relaunch after wake from sleep: off(this might not be effective)
quarkw commented 8 months ago

The same goes for me. The solution for now is to delete this application all at once with the following command. This happens with Karabiner-Element 14.13.0 and the Karabiner-MultitouchExtension that comes with this.

> killall Karabiner-MultitouchExtension
> sw_vers
ProductName:      macOS
ProductVersion:       14.2.1
BuildVersion:     23C71

My configurations are:

  1. Open at login: off
  2. Relaunch after wake from sleep: off(this might not be effective)

You get this issue when you have Open at login off for the multitouch extensions? Are you manually launching the extension? Or this is happening even when you don't launch or intend to launch the multitouch extension?

nowaq commented 8 months ago

I'm having the same issue. Karabiner spawns hundreds if not thousands of Karabiner-MultitouchExtension processes. I can't really tell because the thread pool of the system is exhausted and terminal wouldn't start.

Each process is 96KB according Activitiy Monitor.

Some other apps also won't start or their functions get impaired.

Super annoying. I found out that if I catch this happening early enough closing Karabiner doesn't change anything, but starting it again seems to kill the orphaned processes. It does not work when the thread pool is exhausted. Only restart works then.

I have Open at login: on. I also use CleanMyMac to run some maintenance scripts on my mac, so perhaps it interferes with this issue. Thanks!

quarkw commented 7 months ago

Here's my (unverified) hack to stop this issue from making your computer unresponsive

It's a simple shell script that checks the number of karabiner multitouch processes. If there's more than 5, it will kill all existing multitouch processes and start it up again.

#!/bin/bash
process="Karabiner-MultitouchExtension"
count=$(ps aux | grep -v "grep" | grep -c $process)

if [ $count -gt 5 ]; then
  killall $process
  open '/Library/Application Support/org.pqrs/Karabiner-Elements/Karabiner-MultitouchExtension.app'
fi

Here's an example launchd plist to have it run every 30 seconds

titled com.quarkw.karabiner-elements.cull

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.quarkw.karabiner-elements.cull</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/top/cull-karabiner-mt.sh</string>
    </array>
    <key>StartInterval</key>
    <integer>30</integer>
</dict>
</plist
sudo cp com.quarkw.karabiner-elements.cull.plist /Library/LaunchDaemons/
launchctl load -w /Library/LaunchDaemons/com.quarkw.karabiner-elements.cull.plist

I just whipped this up and added it as a launch daemon, so I don't know if it works but it should in theory.

I tested it by using open -n -a /Library/Application\ Support/org.pqrs/Karabiner-Elements/Karabiner-MultitouchExtension.app/ to open a bunch of instances and it works, and 30 seconds should be frequent enough to catch the processes before it gets out of control

roachsinai commented 7 months ago

Having same issue!

externvoid commented 7 months ago

I found that this issue can be avoided by following a certain procedure to enter the sleep state.

  1. Using the Touch ID button for sleeping does not cause this app to spawn multiple instances.

  2. The iokit_power_management_sleep_system function in the Karabiner-Elements software triggers this issue.

blech75 commented 3 months ago

👋 i'm having the same problem macOS 14.5 (23F79), though luckily i have not (yet) experienced exhausting the thread pool.🤞

for now i'm using @quarkw's solution above (thanks so much!), modified slightly to avoid touching files/services outside $HOME.


seems like launchctl has been updated since the last time i messed around with it (a few macOS versions ago) and even after reading the man page five times, i could not figure out how to use the new commands (bootstrap, etc.) correctly. after ~30m i gave up and used load, and it seems to work fine. 🤷