Repository navigation
Description
Our github action to run rubocop started failing when parallel was upgraded from 1.25.1 to 1.26.0
This is the error seen
Run bundle exec rubocop --parallel
negative array size
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.0/lib/parallel.rb:581:in `initialize'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.0/lib/parallel.rb:581:in `new'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.0/lib/parallel.rb:581:in `create_workers'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.0/lib/parallel.rb:520:in `work_in_processes'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.0/lib/parallel.rb:291:in `map'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.0/lib/parallel.rb:235:in `each'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:103:in `warm_cache'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:76:in `run'
/home/runner/work/sm-web/sm-web/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
...snip...
I presume this is because of the following change that uses Concurrent.available_processor_count.floor to determine the number of available processors if the gem concurrent-ruby is installed, which in my case it is.
I can see that I can use the environment variable PARALLEL_PROCESSOR_COUNT to override this behaviour for my configuration but I think there is an issue here to be understood and mitigated around the behaviour in github actions. Whilst I appreciate the incorrect value may come from concurrent-ruby, I think perhaps that parallel should handle a negative value in a different way. Perhaps by failing back to using Etc.nprocessors as the previous version did.
I have not created a PR for this because I felt it needed discussion and knowledge from those that understand parallel vastly more than I do.
Activity
mark-young-atg commentedon Aug 8, 2024
As a further comment on this, I checked our Amazon AWS instance and the use of
Concurrent.available_processor_count.floorlooks as though it will cause problems by returning a negative number. This is what I see on our ECS instance:grosser commentedon Aug 8, 2024
ovston commentedon Aug 8, 2024
Same issue
mark-young-atg commentedon Aug 8, 2024
Thank you very much @grosser. I think that was a sensible move.
mark-young-atg commentedon Aug 8, 2024
@grosser although I think it might be sensible to fix forward by releasing v1.26.1 which reverts that commit. The reason being I'm still finding that
bundle updateandbundle installtry to give me v1.26.0, possibly due to the gem still being installed locally on my laptop. Obviously I know to remove it withgem uninstall parallel:1.26.0but this might catch out others and CI/CD systems.grosser commentedon Aug 8, 2024
Revert "Merge pull request #348 from y-yagi/use_available_processor_c…
grosser commentedon Aug 8, 2024
1.26.1 is out
Fix the return value of `Concurrent.available_processor_count` when `…
Fix the return value of `Concurrent.available_processor_count` when `…
Fix the return value of `Concurrent.available_processor_count` when `…
Fix the return value of `Concurrent.available_processor_count` when `…
eregon commentedon Aug 10, 2024
Concurrent.available_processor_countis now fixed upstream and released: ruby-concurrency/concurrent-ruby#1060Sorry for the bug!
grosser commentedon Aug 11, 2024
re-released as v1.26.2 🤞
honeyankit commentedon Aug 15, 2024
@grosser : I am still getting
negative array sizeerror.Edit: I had to manually update
concurrent-rubyto1.3.4to fix the issue based on the comment heregrosser commentedon Aug 15, 2024
grosser commentedon Aug 15, 2024
... and try updating to latest
bundle update concurrent-rubyand see if that fixes it 🤞VitaliySerov commentedon Aug 16, 2024
Shouldn't
concurrent-rubyv1.3.4 set as minumal version of dependcy of parallel in that case?or rubocop (not sure where the problem comes from)
Ensure not to use old `concurrent-ruby`
eregon commentedon Aug 16, 2024
A simple solution could be to check if
Concurrent.available_processor_countreturns <= 0 and if so useEtc.nprocessors.Or to add concurrent-ruby as a gem dependency to ensure it's always >= 1.3.4.
grosser commentedon Aug 16, 2024
v1.26.3.