lamby icon indicating copy to clipboard operation
lamby copied to clipboard

uninitialized constant Rack::RACK_MULTITHREAD

Open benbonnet opened this issue 2 years ago • 24 comments

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

benbonnet avatar Oct 30 '23 09:10 benbonnet

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

hungnv-sr avatar Nov 01 '23 03:11 hungnv-sr

any updates?

hungnv-sr avatar Nov 13 '23 07:11 hungnv-sr

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)

benbonnet avatar Nov 13 '23 08:11 benbonnet

I experienced the same issue here.

arinhouck avatar Jan 17 '24 22:01 arinhouck

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

albertski avatar Jan 26 '24 18:01 albertski

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.

jeremiahlukus avatar Jun 12 '24 01:06 jeremiahlukus

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!

thenano avatar Jun 27 '24 03:06 thenano

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.

jeremiahlukus avatar Jun 27 '24 04:06 jeremiahlukus

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.

thenano avatar Jun 27 '24 04:06 thenano

Im able to reproduce

jeremiahlukus avatar Jun 27 '24 11:06 jeremiahlukus

lol so looking at the rack changelog

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

  • Introduce Rack::VERSION constant. (https://github.com/rack/rack/pull/2199, @ioquatix)

They added back the Rack::VERSION constant.

jeremiahlukus avatar Jun 27 '24 12:06 jeremiahlukus

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

jeremiahlukus avatar Jun 27 '24 20:06 jeremiahlukus

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

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

jeremiahlukus avatar Jun 28 '24 00:06 jeremiahlukus

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

jeremiahlukus avatar Jun 28 '24 01:06 jeremiahlukus

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

jeremiahlukus avatar Jun 28 '24 01:06 jeremiahlukus

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 avatar Jun 28 '24 02:06 thenano

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?

thenano avatar Jun 28 '24 02:06 thenano

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

jeremiahlukus avatar Jun 28 '24 02:06 jeremiahlukus

@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?

thenano avatar Jun 28 '24 02:06 thenano

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.

jeremiahlukus avatar Jun 28 '24 04:06 jeremiahlukus

@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?

thenano avatar Jun 28 '24 04:06 thenano

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

I'm in this statement too 😅

metaskills avatar Jun 28 '24 11:06 metaskills

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 avatar Jun 28 '24 16:06 jeremiahlukus

working on it again today making progress

jeremiahlukus avatar Jul 02 '24 15:07 jeremiahlukus

@thenano hey I got it working on my app now

https://github.com/jeremiahlukus/lamby

Can you try again. I realized I was hitting my cloud front app so some things were getting cached when i hit api gateway directly i was able to reproduce consistently. After a good bit of fiddling I finally got it to work with rack v3 (pulling from master).

jeremiahlukus avatar Jul 09 '24 20:07 jeremiahlukus

Or @metaskills if you have an app running on rack v2 and want to test v3 that would be great.

jeremiahlukus avatar Jul 09 '24 20:07 jeremiahlukus

Deployed in 3 apps so far no issues, I also tested on a rack v2 app and it seems to be working.

jeremiahlukus avatar Jul 09 '24 20:07 jeremiahlukus

Hey @jeremiahlukus thanks again for all your work on this. I have tested with rack 3.1.4 and 3.1.6. "Normal" rails controller calls are returning correctly (i.e. I can get html and data) but I'm getting errors when serving any assets, I get 500s for all js and css files served via the app:


2024-07-10T12:31:30.089+10:00 | Error raised from handler method
-- | --
  | 2024-07-10T12:31:30.089+10:00 | {
  | 2024-07-10T12:31:30.089+10:00 | "errorMessage": "source sequence is illegal/malformed utf-8",
  | 2024-07-10T12:31:30.089+10:00 | "errorType": "Function<JSON::GeneratorError>",
  | 2024-07-10T12:31:30.089+10:00 | "stackTrace": [
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/lib/ruby/3.3.0/json/common.rb:305:in `generate'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/lib/ruby/3.3.0/json/common.rb:305:in `generate'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/json/encoding.rb:92:in `stringify'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/json/encoding.rb:41:in `encode'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/json/encoding.rb:23:in `encode'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/core_ext/object/json.rb:42:in `to_json'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric/aws_lambda_marshaller.rb:30:in `marshall_response'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric/lambda_handler.rb:31:in `call_handler'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric.rb:81:in `run_user_code'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric.rb:59:in `start_runtime_loop'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric.rb:42:in `run'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric/bootstrap.rb:35:in `bootstrap_handler'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric/bootstrap.rb:8:in `start'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/gems/aws_lambda_ric-2.0.0/bin/aws_lambda_ric:10:in `<top (required)>'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/bin/aws_lambda_ric:25:in `load'",
  | 2024-07-10T12:31:30.089+10:00 | "/usr/local/bundle/bin/aws_lambda_ric:25:in `<main>'"
  | 2024-07-10T12:31:30.089+10:00 | ]
  | 2024-07-10T12:31:30.089+10:00 | }

Let me know if you need any more info or if I need to change anything.

Thanks!

thenano avatar Jul 10 '24 02:07 thenano

Just to make sure does your app work with the published version using rack v2?

and does your app differ from the configuration https://github.com/rails-lambda/lamby-cookiecutter/blob/master/%7B%7Bcookiecutter.project_name%7D%7D/config/environments/production.rb

And are you pre compiling in your deploy script and coping those files in your dockerfile?

I also have config.public_file_server.enabled = true in my config.

my app uses active admin and that css and is is loading so either your app is configured wrong or you are loading assets a different way and I’m not accounting for that in my fork of lamby

jeremiahlukus avatar Jul 10 '24 12:07 jeremiahlukus

In the attached pic i have css to make the panels red then some js to turn them a light blue on hover.

Screenshot 2024-07-10 at 9 34 10 AM

added some custom js and css to active admin. Still no issue

Screenshot 2024-07-10 at 9 35 36 AM

Assets all are 200's as well

jeremiahlukus avatar Jul 10 '24 13:07 jeremiahlukus