Skip to content

Gruf.controllers_path config breaks integration with Rails #215

@salmanasiddiqui

Description

@salmanasiddiqui

Please describe the issue

https://github.com/bigcommerce/gruf/blob/main/lib/gruf/integrations/rails/railtie.rb#L26

The above file adds an intializer which is invoked before_configuration. The initializer is supposed to modify the Rails autoloader and ignore Gruf.controllers_path from it.

But Gruf.controllers_path is supposed to be configured within an intializer. The before_configuration hook is too early in the life cycle, and at this stage none of the intializers are executed. So the above file always end up ignoring the default controllers_path from Rails autoloader.

Rails intializer hooks are:

  1. before_configuration
  2. before_initialize
  3. before_eager_load (only executed if eager_load=true)
  4. prepare_to (executed on each request in dev environment, executed once on boot in others)
  5. after_initialize

Instead of before_configuration I think this should depend on eager_load config. And it should be something like

if config.eager_load
  before_eager_load { ..."setup the rails autoloader and eager load paths" }
else
  after_initialize { ..."setup the rails autoloader and eager load paths" }
end

How to Reproduce

Steps to reproduce the behavior:

  1. Initialize new rails app
  2. Add gruf to it
  3. add gruf.rb to config/initializers
Gruf.configure do |c|
  c.controllers_path = "app/my_custom_rpc_dir"
end
  1. create app/my_custom_rpc_dir and add a Grpc service to it
  2. run bundle exec gruf
  3. see error regarding zietwerk conflict

What should happen?

bundle exec gruf should run successfully as the configuration is correct

Anything else we should know?

  • gRPC version
  • Ruby version
  • OS
  • Does it occur at certain traffic volumes, payload size, etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions