Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawning crystal process leads to out of memory #11

Closed
akwiatkowski opened this issue May 7, 2024 · 1 comment
Closed

spawning crystal process leads to out of memory #11

akwiatkowski opened this issue May 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@akwiatkowski
Copy link

akwiatkowski commented May 7, 2024

hello.

Running crystal code spawns a lot of crystal processes which looks like fork bomb and within few second I'm out of RAM. I didn't have time to try to troubleshoot nor analyze crystalruby code.

spawned more than 40 processes (ps -ax | grep crystal):

crystal build --single-module --link-flags -shared -o <local path>/crystalruby/crystalruby/lib/crystalruby_2740b21ad0d3ecda509d3b50bda329dc <local path>/crystalruby/crystalruby/src/crystalruby.cr

after exiting ruby process and killing crystal processes ruby stack:

        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/compilation.rb:17:in `compile!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/library.rb:157:in `block in build!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/library.rb:150:in `synchronize'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/library.rb:150:in `build!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/function.rb:34:in `block (2 levels) in define_crystalized_methods!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/function.rb:35:in `block (2 levels) in define_crystalized_methods!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/function.rb:35:in `block (2 levels) in define_crystalized_methods!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/function.rb:35:in `block (2 levels) in define_crystalized_methods!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/function.rb:35:in `block (2 levels) in define_crystalized_methods!'
        from /home/olek/.rvm/gems/ruby-3.1.2/gems/crystalruby-0.2.0/lib/crystalruby/function.rb:35:in `block (2 levels) in define_crystalized_methods!'
...

sample code which leads to error:

require 'crystalruby'

module MyTestModule
  # The below method will be replaced by a compiled Crystal version
  # linked using FFI.
  crystalize [a: :int, b: :int] => :int
  def add(a, b)
    a + b
  end
end

# This method is run in Crystal, not Ruby!
MyTestModule.add(1, 2) # => 3

Used on ruby 3.3 and 3.1.2, crystal 1.12.1 on gnu/debian.

@wouterken
Copy link
Owner

Thank you for your report @akwiatkowski, I was able to reproduce the behaviour on a system running Debian 12, and have pushed version 0.2.3 which appears to address the issue (seems mishandling of compilation process output was causing the Ruby code to progress prematurely before the compiled assets were ready, causing infinite recursion).

https://github.com/wouterken/crystalruby/releases/tag/0.2.3

Please feel free to report back with more information if the issue still persists for you.

@wouterken wouterken added the bug Something isn't working label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants