Skip to content

Commit

Permalink
Eagerly require set in thread_pool.rb
Browse files Browse the repository at this point in the history
Lazily requiring it in this matter can break rake whenever
a rake task limits access to the file system.  For example:

```ruby
task :default do
  Dir.chroot Dir.pwd
end
```

One reason to lazily require this is to save on memory, but
since Rake::Application appears to always use a thread pool
(Rake::Application#run -> top_level -> run_with_threads ->
thread_pool), it doesn't looks like lazily requiring actually
saves memory in this case.
  • Loading branch information
jeremyevans authored and hsbt committed Jul 19, 2022
1 parent 2cda976 commit 4d3b5d7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rake/thread_pool.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "rake/promise"
require "set"

module Rake

Expand All @@ -9,7 +10,6 @@ class ThreadPool # :nodoc: all
# Creates a ThreadPool object. The +thread_count+ parameter is the size
# of the pool.
def initialize(thread_count)
require "set"
@max_active_threads = [thread_count, 0].max
@threads = Set.new
@threads_mon = Monitor.new
Expand Down

0 comments on commit 4d3b5d7

Please sign in to comment.