Use Thread.start to avoid "can't alloc thread" error #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the change
Use
Thread.start
instead ofThread.new
to avoid thecan't alloc thread
error under specific conditions.Why are we doing this?
Under these conditions, the
can't alloc thread
error occurs:Command#run
in a non-main threadCommand#run
withThread#join
Command#run
is executingCommand#run
again in an error handler that processes the interruptHere is a reproduction example:
The result is as follows. The
echo cleanup...
is not executed:It should work like this👇️:
echo cleanup...
should be executed and should also be stoppable with Ctrl+C.(The verbose error messages from read_streams are problematic, but let's consider that a separate issue.)
Benefits
This fixes the error.
Drawbacks
All existing tests pass, so existing code should continue to work correctly.
Requirements
master
branch?Additional Notes
Thread.new
andThread.start
should behave exactly the same way in how tty-command uses them. I don't understand why simply switching tostart
prevents the error from occurring. This is more of a workaround for a Ruby interpreter bug rather than a tty-command bug.https://ruby-doc.org/core-2.5.9/Thread.html