rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Mounted rack apps breaks when deployed to AWS (bug not present locally) #616

Closed wivarn closed 1 year ago

wivarn commented 2 years ago

Checklist

My Environment

I am upgrading Jets from 3.0.0 to 3.1.1


Expected Behaviour

Jets should not be throwing a ArgumentError

Current Behavior

Stacktrace:

{
    "errorMessage": "wrong number of arguments (given 3, expected 2)",
    "errorType": "Function<ArgumentError>",
    "stackTrace": [
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/controller/rack/adapter.rb:13:in `initialize'",
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/internal/app/controllers/jets/bare_controller.rb:13:in `new'",
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/internal/app/controllers/jets/bare_controller.rb:13:in `process!'",
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/controller/base.rb:35:in `process'",
        "app/controllers/jets/mount_controller.rb:1:in `run'",
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/processors/main_processor.rb:32:in `instance_eval'",
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/processors/main_processor.rb:32:in `run'",
        "/opt/ruby/gems/2.7.0/gems/jets-3.1.1/lib/jets/core.rb:120:in `process'",
        "/var/task/handlers/controllers/jets/mount_controller.rb:6:in `call'"
    ]
}

Step-by-step reproduction instructions

Mount any rack app, deploy it and hit the endpoint

Solution Suggestion

Seems like the bug was introduced in this commit https://github.com/boltops-tools/jets/commit/fcda68924d61d5739f691a67228db72afb850c01 meth was removed as an argument in multiple places but it appears this place was missed https://github.com/boltops-tools/jets/blob/master/lib/jets/internal/app/controllers/jets/bare_controller.rb#L13

I tested and verified the following monkey patch fixes this issue:

module Jets
  module BareControllerExtentions
    private

    def process!
      status, headers, body = dispatch!
      adapter = Jets::Controller::Rack::Adapter.new(event, context)
      adapter.convert_to_api_gateway(status, headers, body)
    end
  end

  class BareController
    prepend BareControllerExtentions
  end
end

However, I'm not too familiar with the codebase so I'm not sure if this is the correct/best place to fix the bug. This can probably fixed further up or down the callstack.

benforeva commented 1 year ago

I'm getting this error as well using Jets 3.0.23.

Did you have to revert to a lower version or did you have another workaround?

benforeva commented 1 year ago

I reset jets to a commit before this one where both errors affecting mounted rack apps are not present and published it as a gem. Anyone facing this issue can use this in the interim.

tongueroo commented 1 year ago

@wivarn Thanks for the detailed report. The line you identify was the fix. Appreciate it.