socketry / falcon

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

Railtie not loading #256

Open p8 opened 2 days ago

p8 commented 2 days ago

I've added Falcon to the Rails TechEmpower benchmark: https://github.com/TechEmpower/FrameworkBenchmarks/pull/9339

I had to set the isolation_level to :fiber by hand to make it work. https://github.com/p8/FrameworkBenchmarks/blob/f7822a3d79689164e372fba05be4ee744b1f42a4/frameworks/Ruby/rails/config/application.rb#L55

Otherwise the following error would occur:

$ ./tfb --test rails-falcon --mode verify
...
rails-falcon: {"time":"2024-10-23T08:13:36+00:00","severity":"error","oid":3416,"pid":18,"subject":"Protocol::Rack::Adapter::Rack3","annotation":"Reading HTTP/1.1 requests for Async::HTTP::Protocol::HTTP1::Server.","event":{"type":"failure","root":"/rails","class":"NoMethodError","message":"\u001b[1mundefined method 'map_types!' for nil (\u001b[1;4mNoMethodError\u001b[m\u001b[1m)\u001b[m\n\n\u001b[1m              result = conn.async_exec(sql).map_types!(@type_map_for_results).values\u001b[m\n\u001b[1m                                           ^^^^^^^^^^^\u001b[m","backtrace":
["/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:19:in 'block (2 levels) in ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements#query'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1004:in 'block in ActiveRecord::ConnectionAdapters::AbstractAdapter#with_raw_connection'",
"/usr/local/bundle/gems/activesupport-7.2.1.1/lib/active_support/concurrency/null_lock.rb:9:in 'ActiveSupport::Concurrency::NullLock#synchronize'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:976:in 'ActiveRecord::ConnectionAdapters::AbstractAdapter#with_raw_connection'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:18:in 'block in ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements#query'",
"/usr/local/bundle/gems/activesupport-7.2.1.1/lib/active_support/notifications/instrumenter.rb:58:in 'ActiveSupport::Notifications::Instrumenter#instrument'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1119:in 'ActiveRecord::ConnectionAdapters::AbstractAdapter#log'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:17:in 'ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements#query'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:110:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#query_values'",
"/usr/local/bundle/gems/activerecord-7.2.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:35:in 'ActiveRecord::ConnectionAdapters::SchemaStatements#data_sources'"
ioquatix commented 2 days ago

I wonder if it's load order dependent?

https://github.com/socketry/falcon/blob/main/lib/falcon.rb#L10

p8 commented 2 days ago

Yes, it could be that Rails isn't loaded there yet.

ioquatix commented 2 days ago

I wonder what the best strategy would be, e.g.

begin
  require 'railtie'
  ...
rescue LoadError 
  # Ignore
end