rails-lambda / lamby

🐑🛤 Simple Rails & AWS Lambda Integration
https://lamby.cloud
MIT License
590 stars 30 forks source link

uninitialized constant Rack::RACK_MULTITHREAD #171

Open benbonnet opened 8 months ago

benbonnet commented 8 months ago

Using rails 7.1.1, rack (3.0.8) and lamby (~> 5.2) Hard to get why those happen; I created a fresh app following the getting started and deploying via github actions. It does deploy without issues, but invariably getting the following error :

Executing 'config/environment.Lamby.cmd' in function directory '/app'
...
"errorMessage": "uninitialized constant Rack::RACK_MULTITHREAD"
...
2023-10-30T01:36:10.282+01:00 "/app/vendor/bundle/ruby/3.2.0/gems/lamby-5.2.0/lib/lamby/rack_http.rb:45:in `env_base'"
...

Went through the rack code trying to find Rack::RACK_MULTITHREAD; not to be found

Then further below :

Init error when loading handler
--
  | 2023-10-30T01:36:10.282+01:00 | {
  | 2023-10-30T01:36:10.282+01:00 | "errorMessage": "wrong number of arguments (given 4, expected 2..3)",

This one looks related

hungnv-sr commented 8 months ago

Same issue: https://github.com/rails-lambda/lamby-cookiecutter/issues/41

hungnv-sr commented 7 months ago

any updates?

benbonnet commented 7 months ago

downgrading / forcing down rack to 2.2.6.4 clears the issue; but it surely does not work with latest rack (= default installed for a new rails app seems like 3.0.x)

arinhouck commented 5 months ago

I experienced the same issue here.

albertski commented 5 months ago

I experienced this as well. I removed the constants in https://github.com/rails-lambda/lamby/pull/173 and it fixed the issue.

jeremiahlukus commented 3 weeks ago

Going to look at this tomorrow and get it merged after testing on lower rack versions to make sure it doesn't break anything. If it does i need to set a rack restraint and it will be a major version change with a breaking change.

thenano commented 1 week ago

Hi @jeremiahlukus thanks for looking into this and pushing a fix! I'm not sure if I'm doing anything wrong, but I updated to lamby 5.1.2, and I'm still getting errors when trying to run with Rack 3.1.4, getting the following in my logs:


2024-06-27T13:27:52.055+10:00 | {
-- | --
  | 2024-06-27T13:27:52.055+10:00 | "errorMessage": "uninitialized constant Rack::VERSION",
  | 2024-06-27T13:27:52.055+10:00 | "errorType": "Function<NameError>",
  | 2024-06-27T13:27:52.055+10:00 | "stackTrace": [
  | 2024-06-27T13:27:52.055+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/lamby-5.2.1/lib/lamby/rack_http.rb:41:in `env_base'",
  | 2024-06-27T13:27:52.055+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/lamby-5.2.1/lib/lamby/rack.rb:33:in `env'",
  | 2024-06-27T13:27:52.055+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/lamby-5.2.1/lib/lamby/handler.rb:89:in `call_app'",
...

Let me know if I'm doing something wrong or if I can provide any additional information.

thanks again!

jeremiahlukus commented 1 week ago

Seems like more conta were removed

https://github.com/rails-lambda/lamby/blob/master/lib/lamby/rack_http.rb#L41

I only tested on older rack versions since my app uses an older rack version. I should have tested on older and newer to verify the PR actually fixes the issue. I should have some time tomorrow to spin up a new app and test. I’ll fix this in the next couple days.

More than happy to look over a PR if you want it in faster.

thenano commented 1 week ago

Thanks @jeremiahlukus I'm not in any rush, was just going through my open PRs for dependency upgrading. I'm happy to wait a couple of days. I you do need help after that let me know.

jeremiahlukus commented 1 week ago

Im able to reproduce

jeremiahlukus commented 1 week ago

lol so looking at the rack changelog

https://github.com/rack/rack/blob/main/CHANGELOG.md#added

They added back the Rack::VERSION constant.

jeremiahlukus commented 1 week ago

for some reason getting status 0 when using the newest rack version no idea why.

jeremiahlukus commented 1 week ago

@thenano can you see if my branch fixes it for you?

gem 'lamby', git: 'https://github.com/jeremiahlukus/lamby'

jeremiahlukus commented 1 week ago

Ok finally fixed it that took longer than i'd like to admit. Ill send another PR

jeremiahlukus commented 1 week ago

https://github.com/rails-lambda/lamby/pull/180

thenano commented 1 week ago

Hey @jeremiahlukus thanks so much for looking into this! Sorry about the delay in getting back to you. I have tested your branch and although in the end I'm getting a 500 response, checking lamby logs it all seems to be running fine, so something else might have broken in my setup which I'll look into. Happy to do any more testing if you need.

thenano commented 1 week ago

it looks like API Gateway is not happy with the response sent from lambda:

{"httpMethod":"GET","integrationErrorMessage":"The response from the Lambda function doesn't match the format that API Gateway expects. Lambda body contains the wrong type for field "multiValueHeaders"","protocol":"HTTP/1.1","requestId":"aDkFrj1KywMEPUA=","requestTime":"28/Jun/2024:02:04:20 +0000","resourcePath":"-","responseLength":"35","routeKey":"$default","sourceIp":"220.245.90.202","status":"500"}

Not sure if related, or maybe something that rack has changed?

jeremiahlukus commented 1 week ago

Hm i think i need to ensure multiValueHeaders is always a hash. I just pushed do you mind trying the latest?

thenano commented 1 week ago

@jeremiahlukus I'm still getting the same error, I'm pretty sure it built with the latest from your branch, but if you wanted to add a tag or something like that I could force a version and check?

jeremiahlukus commented 1 week ago

I closed the PR still have a weird issue on my end as well. I’m not seeing the error you are seeing however. If you can debug a bit that would be helpful.

thenano commented 1 week ago

@jeremiahlukus interesting, happy to help with debugging. essentially I keep getting that same error on the GW side. Can you point me in the right direction of where I could potentially dump some information into logs to get more insight into it?

metaskills commented 1 week ago

Ok finally fixed it that took longer than i'd like to admit. Ill send another PR

I'm in this statement too 😅

jeremiahlukus commented 1 week ago

Whats weird is some requests a passing and some are returning status 0 and 302. Having a hard time figuring out if its because of my app or lamby ha

jeremiahlukus commented 6 days ago

working on it again today making progress