Rails 4.2: Internal Server Error with Maximum file multiparts in content reached
Asked Answered
C

4

45

Just upgraded to Rails 4.2 and I get Internal Server Error on localhost and in production when trying to edit a model with multiple has_many objects. This is the message I see on the rails s console

!! Unexpected error while processing request: Too many open files - Maximum file multiparts in content reached

The request does not even get to the controller i.e., I DO NOT see the usual following lines in rails s console

Started GET "/feeds/3/edit" for 127.0.0.1 at 2015-01-04 20:07:19 -0800
Processing by FeedsController#edit as HTML
......
......

Any clues?? Using Ruby 2.1.5 upgraded to 2.2 with no luck.

Caltanissetta answered 5/1, 2015 at 4:20 Comment(2)
Getting the same thing here, Rails 4.2.0 and Ruby 2.2.0.Luz
Rack 1.6.4 contains a fix for this.Gilead
L
74

It looks like the multipart limit was added in the Rails 4.2 version of Rack (https://github.com/rack/rack/commit/b0b5fb9467e6ed777d3eaf35afc81d758e308aab). The default is 128, which may be too little for your purposes, it was for mine. Setting the value to 0 in an initializer removes the limit and fixes the problem:

Rack::Utils.multipart_part_limit = 0

I would suggest tailoring the value until it fits your needs so your server doesn't run out of file handles. My app uses a massive form and setting it to 512 seemed to work for me.

Luz answered 5/1, 2015 at 17:15 Comment(6)
Thank you Craig. Will test and mark your answer as accepted if it works. I do have a long form. The shorter forms work fine.Caltanissetta
It looks to us like the patch that was introduced is counting one open file per form element, not just files. So if you have a nested form, you quickly run out of "files". Seems like a bad patch.Vaporous
Rack 1.6.1 does NOT contain this fix. Looks like that will be in the 1.7 release instead :(Gilead
Rack 1.6.4 contains a fix for this.Gilead
Hey i m facing the same problem,Where i can place this line?Rife
@JigarBhatt I place it in config.ru, for referenceAli
P
14

You can also pass a Environment variable to the app, as you can see here(https://github.com/rack/rack/blob/8d21788798b521b97beb10047ebf593ddc0aaed2/lib/rack/utils.rb#L75).

RACK_MULTIPART_PART_LIMIT=0 rails server

Parturient answered 14/1, 2015 at 13:12 Comment(3)
But you should set both RACK_MULTIPART_PART_LIMIT and RACK_MULTIPART_LIMIT because of the code remark RACK_MULTIPART_LIMIT was introduced by mistake and it will be removed in 1.7.0Mesial
Hey i m facing the same problem,Where i can place this line?Rife
@JigarBhatt you can set this env variables on the line that you execute your script. For example: RACK_MULTIPART_PART_LIMIT=0 ruby app.rb or you can export you variable an then run your script. export RACK_MULTIPART_PART_LIMIT=0 then ruby app.rbParturient
G
6

It looks like there is a bug in Rack 1.6 where all HTML input elements get counted as an open file in a multipart form. As others point out, you can change the limit to 0 to disable the feature, or bump the limit.

https://github.com/rack/rack/pull/814

Gilead answered 2/3, 2015 at 20:53 Comment(1)
This has been merged into 1.6.4 it appearsGilead
P
0

In Rails > 6 you will need to use multipart_total_part_limit instead of multipart_part_limit.

Rack::Utils.multipart_total_part_limit = 0

Source

Papain answered 16/7, 2024 at 10:19 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.