kepler155c / opus-apps

Computercraft Applications for Opus OS
MIT License
32 stars 28 forks source link

Fix: too many milo parallel tasks hurting server #46

Closed Lemmmy closed 4 years ago

Lemmmy commented 4 years ago

We had a player on SwitchCraft recently with >500 chests in their Milo. Milo does a pretty good job of throttling things to avoid hurting the server in this case, however, it relies on a single peripheral.waitForAll call to wait for all the throttles to complete. This ended up spawning 480 coroutine threads for this particular user's Milo:

By reaching the thread limit, these parallel calls actually never finished, causing the user to try to boot-loop their Milo until it would work, causing more damage. We also got alerts about it every 5 minutes on the staff Discord :P

In this patch, I've chunked the tasks in Storage:listItems() to only run 16 at a time. This limit might need to be tuned, but in my testing it runs just as fast, and doesn't spawn infinite threads in the process.