rubyjs / mini_racer

Minimal embedded v8
MIT License
585 stars 91 forks source link

Dealing with "WARNING: V8 isolate was forked" with rspec rake test #254

Closed Faq closed 1 year ago

Faq commented 2 years ago

Hello, Rails 7 Ruby 3.1

Migrated to ruby v3.1 and also changed gem from therubyracer to _miniracer 0.6.2, no other changes were done.

Searching for: MiniRacer::Context It is found only used in gem execjs v2.8.1

WARNING: V8 isolate was forked, it can not be disposed and memory will not be reclaimed till the Ruby process exits.
It is VERY likely your process will hang.
If you wish to use v8 in forked environment please ensure the platform is initialized with:
MiniRacer::Platform.set_flags! :single_threaded

Running all tests getting several such warnings for this exact test file(running only this single file not triggers warning), file content:

require File.expand_path('../../../config/application', __FILE__)
require 'brakeman'

RSpec.describe 'Brakeman Issues' do
  it 'Application must not have Critical Security Issues' do
    output_file = 'tmp/brakeman_app_report.html'
    result = Brakeman.run(
      app_path:       Rails.root.to_s,
      run_all_checks: true,
      output_files:   [output_file]
    )
    counts = warnings_count(result.filtered_warnings)

    if counts[:total] > 0
      output_path = Rails.root.join(output_file)
      puts "====> Brakeman App Warnings found: #{counts[:total]}. You can review them at #{output_path}"
    end

    expect(counts[:critical]).to eq 0
  end

  def warnings_count(warnings)
    {
      total:    warnings.count,
      critical: warnings.count { |w| w.confidence == 0 }
    }
  end
end

Problem: For me is not clear where should I put this line in such case. MiniRacer::Platform.set_flags!(:single_threaded)

tisba commented 2 years ago

It's unclear from your description where you're using mini_racer, @Faq.

In a Rails-based project where I'm using mini_racer directly, putting MiniRacer::Platform.set_flags!(:single_threaded) was sufficient. Where are you currently calling it from?

Faq commented 1 year ago

Thnx, checked and looks like for this old project it is not needed anymore as wasn't even running. That is what you get blindly upgrade gems with rails/ruby.