bjfish
(Brandon Fish)
April 28, 2022, 5:06pm
1
I would like to request the following 3 changes to help support running Discourse on TruffleRuby:
Change Requested
Update bin/rails to disable unicorn when fork is not supported.
Error
<internal:core> core/kernel.rb:764:in `fork': fork is not available (NotImplementedError)
Files
bin/rails
#!/usr/bin/env ruby
# frozen_string_literal: true
if !ENV["RAILS_ENV"] && (ARGV[0] == "s" || ARGV[0] == "server")
ENV["UNICORN_PORT"] ||= "3000"
if ARGV[1] == "-p" && (port = ARGV[2].to_i) > 0
ENV["UNICORN_PORT"] = port.to_s
end
ENV["RAILS_LOGS_STDOUT"] ||= "1"
exec File.expand_path("unicorn", __dir__)
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
Why
TruffleRuby do not support forking.
Suggestion
Disable unicorn if !Process.respond_to?(:fork)
========================================================
Change Requested
Disable mini_profiler for TruffleRuby
Error
<internal:core> core/kernel.rb:236:in `gem_original_require': cannot load such file -- stackprof (LoadError)
Files
config/initializers/006-mini_profiler.rb
# frozen_string_literal: true
# If Mini Profiler is included via gem
if Rails.configuration.respond_to?(:load_mini_profiler) && Rails.configuration.load_mini_profiler
require 'rack-mini-profiler'
require 'stackprof'
begin
require 'memory_profiler'
rescue => e
STDERR.put "#{e} failed to require mini profiler"
end
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
end
if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)
# note, we may want to add some extra security here that disables mini profiler in a multi hosted env unless user global admin
# raw_connection means results are not namespaced
This file has been truncated. show original
Why
Stackprof is not currently supported on TruffleRuby
Suggestion
Disable mini_profiler loading when RUBY_ENGINE is âTruffleRubyâ
========================================================
Change Requested
Prevent rbtrace from loading
Similar usages already preventing rb_trace from loading:
config.hosts.concat(hosts.split(","))
end
require 'middleware/turbo_dev'
config.middleware.insert 0, Middleware::TurboDev
require 'middleware/missing_avatars'
config.middleware.insert 1, Middleware::MissingAvatars
config.enable_anon_caching = false
if RUBY_ENGINE == "ruby"
require 'rbtrace'
end
if emails = GlobalSetting.developer_emails
config.developer_emails = emails.split(",").map(&:downcase).map(&:strip)
end
if ENV["DISCOURSE_SKIP_CSS_WATCHER"] != "1" && (defined?(Rails::Server) || defined?(Puma) || defined?(Unicorn))
require 'stylesheet/watcher'
STDERR.puts "Starting CSS change watcher"
@watcher = Stylesheet::Watcher.watch
Error
Failure/Error: require ârbtraceâ
Suggestion
Use one of the methods in the above links to prevent loading rbtrace
Files
spec/rails_helper.rb
SimpleCov.start 'rails' do
add_group 'Libraries', /^\/lib\/(?!tasks).*$/
add_group 'Scripts', 'script'
add_group 'Serializers', 'app/serializers'
add_group 'Services', 'app/services'
add_group 'Tasks', 'lib/tasks'
end
end
require 'rubygems'
require 'rbtrace'
require 'pry'
require 'pry-byebug'
require 'pry-rails'
require 'fabrication'
require 'mocha/api'
require 'certified'
require 'webmock/rspec'
class RspecErrorTracker
def self.last_exception=(ex)
2 Likes
gerhard
(Gerhard Schlager)
April 29, 2022, 12:12pm
5
Those seem like reasonable requests.
BTW: Has anything changed about mini_racer
not being supported on TruffleRuby? Thatâs a major blocker.
Sure I just too care of this there are a few others I left which I am unsure about, what should I do with them? (byebug, ruby-prof, better_errors, rbtrace, gc_tracer, stackprof, memory_profiler)
That said we are totally blocked on truffle till we get mini_racer working per:
https://github.com/oracle/truffleruby/issues/1827
Discourse is not really properly functional if you can not cook Markdown to HTML on the server.
4 Likes
bjfish
(Brandon Fish)
April 29, 2022, 6:55pm
6
BTW: Has anything changed about mini_racer
not being supported on TruffleRuby? Thatâs a major blocker.
I have a branch with most of the mini_racer functionality passing the test suite using using GraalJS for TruffleRuby. I believe it handles all of the functionality needed for Discourse. It just needs to be reviewed and Iâll then Iâll try to get it merged. This is how Iâve been running it locally: x.com
6 Likes
bjfish
(Brandon Fish)
May 2, 2022, 3:44pm
7
Correction:
Disable mini_profiler loading when RUBY_ENGINE is âtrufflerubyâ
2 Likes
sam
(Sam Saffron)
May 3, 2022, 5:04am
8
mini_profiler should still be fine, I would recommend just having us not load rbtrace / stackprof etc. There are loose dependencies.
mini_profiler can still provide plenty value in truffle world, nothing MRI specific about this.
4 Likes
gerhard
(Gerhard Schlager)
May 4, 2022, 8:10pm
9
Hereâs a PR with the requested changes.
discourse:main
â discourse:truffleruby
opened 08:10PM - 04 May 22 UTC
I still couldnât get it to run successfully, there was a java.lang.NullPointerException
, but that might be just me crudely disabling mini_racer. Iâm really looking forward to seeing a fully functional Discourse running on TruffleRuby.
I didnât look into this any further, but I noticed an error when I only disabled loading of stackprof and memory_profiler. So I completely disabled mini_profiler for now.
2022-05-04 21:48:13 +0200 Rack app ("POST /mini-profiler-resources/results" - (127.0.0.1)): #<SystemStackError: stack level too deep
from StackOverflowCheckImpl.java:328:in `com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError0'>
It might have been a side effect of other problems. I guess we could investigate when other problems are solved.
5 Likes