Bug #20779
closedUn-rescuable thread creation limit on Mac
Description
Thread.new will hang the ruby process once past the OSX limit. It does not appear that's possible to trap and rescue failed thread creation.
It seems the Mac has a limit to the number of threads it supports and googling the issue suggests the limit has been known to change with hardware and OS releases. While I hit the thread creation limit due to a bug in my code and the number of threads that I was attempting to create (12,250+) is an unlikely use-case, I am hoping it would be possible to turn this into a rescuable error.
While I'm reporting this on 3.3.5, I have tested the issue and the inability to rescue back to 3.3.1.
(Thanks to @raels for being a great second set of eyes to make sure I wasn't doing anything goofy / wrong before making this report. Also, another callout and thanks to both @Eregon (Benoit Daloze) and @bensheldon over at concurrent-ruby for the unbelievably quick and helpful response to my initial bug report over there).
Files
Updated by luke-gru (Luke Gruber) 25 days ago
I managed to track down the issue, it's a pretty simple fix.
My PR is here: https://github.com/ruby/ruby/pull/12441
Updated by luke-gru (Luke Gruber) 25 days ago
- Status changed from Open to Closed
Applied in changeset git|2a08f7283ed2ca18e25f4b4d19d2f5c6b450c574.
Fix [Bug #20779] Dedicated native thread creation failed bug
When a dedicated native thread fails to create (OS can't create more
threads), don't add the ruby-level thread to the thread scheduler. If
it's added, then next time the thread is scheduled to run it will sleep
forever, waiting for a native thread that doesn't exist to pick it up.