socketry / falcon

A high-performance web server for Ruby, supporting HTTP/1, HTTP/2 and TLS.
https://socketry.github.io/falcon/
MIT License
2.54k stars 79 forks source link

Core methods doesn't work in configuration block after upgrading Falcon to 0.44 #236

Open Exterm1nate opened 2 months ago

Exterm1nate commented 2 months ago

After upgrading Falcon from 0.43 to 0.44 this configuration:

# falcon.rb

load :rack

rack File.basename(__dir__) do
  endpoint do
    Async::HTTP::Endpoint.for(scheme, "0.0.0.0", port: Integer(3000), protocol: protocol)
  end
  count Integer(2)
end

breaks server boot with a very strange error:

/home/kirill/gems/ruby-3.3.0/gems/async-service-0.12.0/lib/async/service/environment.rb:124:in `block (2 levels) in wrap': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from /home/kirill/Desktop/my_project/falcon.rb:7:in `block (2 levels) in load_file'
    from /home/kirill/gems/ruby-3.3.0/gems/async-service-0.12.0/lib/async/service/environment.rb:125:in `block (2 levels) in wrap'
    from /home/kirill/gems/ruby-3.3.0/gems/falcon-0.45.2/lib/falcon/service/server.rb:38:in `start'
    from /home/kirill/gems/ruby-3.3.0/gems/async-service-0.12.0/lib/async/service/controller.rb:48:in `block in start'
    from /home/kirill/gems/ruby-3.3.0/gems/async-service-0.12.0/lib/async/service/controller.rb:47:in `each'
    from /home/kirill/gems/ruby-3.3.0/gems/async-service-0.12.0/lib/async/service/controller.rb:47:in `start'
    from /home/kirill/gems/ruby-3.3.0/gems/async-container-0.18.0/lib/async/container/controller.rb:203:in `run'
    from /home/kirill/gems/ruby-3.3.0/gems/async-service-0.12.0/lib/async/service/controller.rb:32:in `run'
    from /home/kirill/gems/ruby-3.3.0/gems/falcon-0.45.2/lib/falcon/command/host.rb:41:in `call'
    from /home/kirill/gems/ruby-3.3.0/gems/samovar-2.3.0/lib/samovar/command.rb:21:in `call'
    from /home/kirill/gems/ruby-3.3.0/gems/falcon-0.45.2/bin/falcon-host:26:in `<top (required)>'
    from bin/falcon-host:27:in `load'
    from bin/falcon-host:27:in `<main>'

After some investigation I found that configuration block rack {} doesn't support Ruby core methods anymore, e.g. puts, Integer(), etc.

Changing count Integer(2) to count 2 fixes the server boot and works well.

Also it is rather strange that block endpoint {} inside rack {} do support all these methods, that are breaking the rack {} itself. For example, you can use Integer() inside.

# falcon.rb

load :rack

rack File.basename(__dir__) do
  endpoint do
    Async::HTTP::Endpoint.for(scheme, "0.0.0.0", port: Integer(3000), protocol: protocol)
  end
  count 2
end

I suppose this should be fixed or at least mentioned in docs.

ioquatix commented 2 months ago

Yep that's a fair point, and a fair request. I'll think about the best way forward.

Part of the design motivation is to ensure we don't accidentally leak shared memory into the configurations, but it's pretty inconvenient. Those configuration blocks are actually re-evaluated every time the child is forked/executed to ensure isolation and predictable behaviour.