EOFError (bad content body) when uploading a file #125

skeevis opened this Issue Apr 29, 2011 · 109 comments


None yet
skeevis commented Apr 29, 2011

When using Paperclip to upload a file, the file upload instantly fails, logging "EOFError (bad content body):"

The exact same operation works with Webrick


Seeing the same thing when handling file uploads manually without paperclip (under rails 3); webrick works fine.

thetron commented May 18, 2011

I was having this issue as well, using carrierwave. Using mongrel or webrick was fine. Upgrading to pow 3.1 seemed to take care of it for me.

raid5 commented May 20, 2011

Updated to Pow 3.1 also. I'm hoping this solves what was a seemingly random error for me. I was only getting this error maybe once every 20-30 uploads.


also seeing this

jrmehle commented May 24, 2011

+1 for this bug.

I did a bit of digging and discovered the issue might be fixed if rack-mount were updated something higher than version 0.6.14 however Rails 3.0.7 specifies "~> 0.6.14" so it is not possible to use anything higher than that in a Gemfile.


jerrod commented Jun 3, 2011

I get this on every upload regardless of file handling lib (carrierwave/paperclip/manual) with pow 0.3.1 and rack-mount 0.6.14


I'm receiving the same problem as well pow 0.3.1, rack-mount 0.8.1, carrierwave 0.5.4

itschn commented Jun 7, 2011

me too pow 0.3.1, rack-mount 0.8.1, paperclip


I know its not a real solution, but I just opted for uploading to S3 instead of local storage.

wnadeau commented Jun 9, 2011

I encountered the same issue with paperclip but realized I had to provide a content_type validation.

After looking at the request from the dev tools in browser, I realized it was only accepting image content types, which was not what I was hoping to upload. (For some reason this is the default for paperclip.)
adding this to my model worked just fine: (all the content types are for browser naming variations)

has_attached_file :audio
validates_attachment_content_type :audio, :content_type => ['audio/mp3', 'application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/mp3','audio/mpg']

rmoriz commented Jul 1, 2011

I run into this bug with a Rails 3.0.9 app and a simple upload field (no paperclip, carrierwave etc plugin) with pow 0.3.1


Had the same issue with 0.3.0. Upgrading to 0.3.1 didn't solve the problem. It made it even worse, cause pow stopped working completely.


I just had this very error.

mikepack commented Jul 8, 2011

+1 Same problem for me

maletor commented Jul 20, 2011


mitio commented Jul 21, 2011


camwest commented Jul 26, 2011



I was getting this error with paperclip. Files at 5mb gave the error. Same files resized down to under 1mb uploaded successfully. I did not test various other sizes to see if there was a tipping point.



awd commented Jul 28, 2011


vrybas commented Jul 31, 2011


wout commented Aug 1, 2011


alopes commented Aug 11, 2011


gdeest commented Aug 22, 2011

Saw this problem too. Works in WebRick. Works in Passenger in production. Works from time to time with Pow, most of the time fails with this very same error.

If I have some time (a very limited resource !) I'll try to make a contrived example that exhibits this problem. But, due to the elusive nature of the problem, I fear it won't show up on the developers' machine...

tdak commented Aug 24, 2011



I too am seeing this on 0.3.2


Happens to me every time I try to upload a file through Paperclip. I'm trying to upload 2.5MB files. Works in WEBrick.

diddeb commented Sep 3, 2011



This is not related to the X-Sendfile bug, is it?

jrmehle commented Sep 3, 2011

@josephers - It's not related to the X-Sendfile bug. This is bugged in Rails 3.0 too.



only happens when uploading video files for me using:

pow 0.3.2
rails 3.0.9
carrierwave 0.5.6

rmoriz commented Sep 7, 2011


I moved away from pow because this bug makes it unusable.



pow is legendary, but this bug is awful ....

@mitio mitio added a commit to mitio/pow that referenced this issue Sep 9, 2011
@mitio mitio Fix bad content body (EOFError) when uploading a file.
Should fix issue #125.

The main issue is duplicated data chunks in the resulting body which gets passed to Nack. The bug can be observed mainly for larger files and depends on async IO events and that's why it is not 100% predictable. The duplication occurs due to redundant re-emitting of the 'data' event by the custom-written util.pause(stream) function.

The custom util.pause()/resume() are needed at least for the tests to pass. When removed from RackApplication#handle, Pow seems to work correctly and does not manifest the bug in question, but the tests within test_rack_application.coffee hang and just timeout. I suppose this is due to the 'end' event not being paused by Stream#pause().
mitio commented Sep 9, 2011

As @tenderlove once said, if all +1's were patches... Indeed, we would be living in a dream :)

Here is the pull request which I believe should fix this problem and along with it the Universe.

Happy coding!


So, should this be resolved by now @mitio @josh? I am still getting this issue, with an upload-form-heavy app, and it makes pow completely unusable. I see 1.3.2 is still the latest version but this pull request (and all the others by mitio) have been rejected because it should be fixed in the next version, correct?

Should I install pow from github if I want to get this working?

mitio commented Oct 11, 2011

@JeanMertz, as I understand it, the idea is to refactor the code so that the custom pause(stream) function is never used, which should resolve the issue. In the meantime, you can use my version of the project as a temporary solution (until a new official pow version is released or until it is fixed in the master branch here).

If I'm not mistaken, you can git clone my repo somewhere, then cd to that folder, run npm install and cake start and it should boot pow from that folder.

hadiS commented Oct 18, 2011

i have the same problem (rails 3.1, pow 0.3.2, carrierwave 0.5.7)

fcoury commented Oct 19, 2011

+1 and this still fails with pow 0.3.2 and vanilla Rails upload.

janko-m commented Oct 27, 2011

About using mitio's repository, I just want to tell you what worked for me. You have to have Homebrew installed for this.

~~- From the "Installation" wiki: install Node.js with brew install node (you may need to add export NODE_PATH="/usr/local/lib/node_modules" to your .bash_profile if Homebrew tells you about it) and npm with curl http://npmjs.org/install.sh | sh.

  • Not from the "Installation" wiki: cd into the cloned mitio's repository, run npm -g install (it searched mine in ruby folder, so you may have to specify the path to the executable (which npm)), run npm -g install, and run cake run (I tried with cake start first, but cake doesn't have that command).~~

I was wrong, I don't know if this worked yet, so I don't do this :P

mitio commented Oct 27, 2011

Hey, guys, thanks to @janko-m I remembered one important thing — you need to use my rewrite-pause-stream branch.

git clone git://github.com/mitio/pow.git && cd pow && git checkout -t origin/rewrite-pause-stream

Then follow the instructions @janko-m has provided. I had to set this up long ago and I don't remember what exactly I needed to install back then. However, I do have cake start/cake stop tasks (at least in my rewrite-pause-stream branch).

janko-m commented Oct 27, 2011

When I installed cake with Homebrew, it didn't list your cake start under commands. Then I realized that the CoffeScript site says that you should just run npm install -g cofee-script, and it will install cake among other things you also need. But now I get an error in the module.js when I run cake, which is probably my fault. Just in case you maybe know, this is the error: http://tinypic.com/r/2ibcjs3/5

I checkouted to the rewrite-pause-stream branch, of course.

mitio commented Oct 27, 2011

@janko-m, when you cd into the cloned repo and checkout the rewrite-pause-stream branch, try running npm install in that folder. This did the trick for me, installing all the project's dependencies (I think this includes cake too). The error you get is because you're missing a module.

janko-m commented Oct 27, 2011

It worked. The npm install didn't work before because I had spaces in the path. I really shouldn't do that ever again :P. So, I have cake start now, and I ran it.
But, unfortunately, I still get this "EOFError (bad content body)". I get it with Sinatra and a plain upload form. I only get it when I try to upload a file the second time. So, if I uploaded a file one time in the past, then erased it in the meanwhile, it is as Pow has somehow memorized that file, and it throws this error after I try to upload it again.

mitio commented Oct 27, 2011

@janko-m, are you sure you're using the pow with my patch? I mean, you're sure you have stopped your system-wide pow installation? If you run cake stop in the cloned repo, your site should stop working if you're using the correct pow version.

Update: Write me a message directly, so that we stop spamming people here.


I'm having this problem with Rails 3.1.1 and Pow 0.3.2. Every file upload fails.

jrz commented Nov 14, 2011

Same here..
rails 3.1.0
0.3.2 every upload



Rails 3.1.1
Pow 0.3.2

pablobm commented Dec 5, 2011


plagi commented Dec 26, 2011

+1 :)

dnch commented Jan 4, 2012

Is there going to be an actual fix for this issue?


+1 - for me it seems to be with files over 1mb.

Rails 3.1.3
Pow 0.4.0 pre
Rack 1.3.6

Standard Rails uploading



Rails 3.2.1

Rack 1.4.1

Pow 06094c6

Also noticing that when the upload fails that I'm seeing a "WARNING: Can't verify CSRF token authenticity" in the log - and Devise [2.0.4] is logging me out. Looks like the request parsing is blowing up.

Work-around by using very small files or using thin/webrick

lpdahito commented Mar 1, 2012


Rails 3.1.1
Rack 1.4.0
Pow 0.3.2

for files over 1mb in size


I also have this problem. I saw this error on my staging and production nginx/passenger configuration, and it turned out I just needed to increase client_max_body_size to something large enough to handle the files uploaded (e.g., 4G).

With pow, if I upload a file that's small enough, I don't have any problems, but if I upload something larger than about 1MB, it breaks. Perhaps some sort of configuration that will allow large file uploads…

bugaiov commented Apr 18, 2012

+1, waiting for the fix


Expected it to fail tonight, but I had no problems. What's changed?

Latest version of pow, Rails 3.2.2, latest version of paperclip. All seems fine. Any one else can confirm?

samuel02 commented May 3, 2012

+1, got the same problem with latest version of Pow, Rails 3.1.3 and Carrierwave.

kojul commented May 21, 2012


Rails 3.2.3, Paperclip 3.0.4, Pow 0.3.2

Also getting "WARNING: Can't verify CSRF token authenticity" and it only fails on files > 1MB.



Rails 3.2.2, Carrierwave 0.6.2, Rack 1.4.1, Pow 0.3.2

got "WARNING: Can't verify CSRF token authenticity" on files more than about 1MB.


The Nack upgrade in Pow master (and the upcoming 0.4.0 release) should fix this problem.

@sstephenson sstephenson closed this Jun 4, 2012
jimiray commented Jun 8, 2012

still getting this after upgrading to 0.4.0


Please distill this to a simple test case so we can reproduce and investigate. I don't have issues uploading files on any of our apps under Pow, but we don't use Carrierwave.

ovelar commented Sep 18, 2012

Upgrading to 0.4.0 fixed this bug where params were not parsed correctly when uploading files over 1mb, or plain-text files with weird (DOS) line endings. Thanks :)


I used powder to update my pow after seeing this thread. I'm now getting a bug where when I upload a file once, it works fine. But when I upload the same exact file the second time, it gives me a nil file in the controller. (FYI we're using CarrierWave, but I'm not sure if that has anything to do with it.) I do not see this problem using Webrick.

@rmm5t rmm5t referenced this issue in carrierwaveuploader/carrierwave-mongoid Jan 15, 2013

Cannot view uploaded picture #73


I am seeing the same issue as @sfsekaran , upload the same file twice, the second time the file in param is nil. also used CarrierWave.

chinito commented May 23, 2013

So, I don't know if it helps. But maybe my experience with the EOF Problem.

We are using Carrierwave so far. When I am uploading the file of the prawn pdf manual, for example, the error occurs. Maybe, this is some solution, which should be reprodruceable for almost everyone. Hope it helps.

phinze commented May 23, 2013

Please distill this to a simple test case so we can reproduce and investigate. I don't have issues uploading files on any of our apps under Pow, but we don't use Carrierwave.

I cooked up a small project to illustrate the issue.


I've yet to be able to reproduce the error 100% reliably, but following the README.md you should be able to see it in action with a couple curl commands you can repeat until they blow up.

I unfortunately haven't yet had the time to familiarize myself with all this pause stuff, but I'm happy to provide any additional information that might aid others.

Hope this helps! 🍻


Just one more +1. Still getting the error uploading large files with Pow 0.4.1, Rails 4.0.0.rc1, Ruby 2.0.0p195 and CarrierWave 0.8.0

Error starting application
Your Rack app raised an exception when Pow tried to run it.
EOFError: bad content body
~/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:117:in `get_current_head_and_filename_and_content_type_and_name_and_body'
~/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:19:in `block in parse'
~/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:17:in `loop'
~/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:17:in `parse'
~/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/multipart.rb:25:in `parse_multipart'

With WEBrick it works fine.

kcm commented Jun 12, 2013

Still seeing this with >2-3MB files with Pow 0.4.1, Rails 3.2.13, ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0], carrierwave 0.8.0.

snow commented Jun 18, 2013

+1 with pow 0.4.1, rails 3.2.13, ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.1.0]

dalpo commented Jun 19, 2013


fermion commented Jun 29, 2013

+1 with pow 0.4.1, Rails 4.0.0 and ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0].





Kequc commented Jul 10, 2013

I thought this was a problem with Rack. Files over 5mb, Pow 0.4.1, Rails 4.0.0, Ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]


Don't know how much this helps, but the error always seems to go away when I enable mitmproxy. AFAIK, mitmproxy buffers the entire request, then forwards it.
It's not especially helpful, given I wanted to use mitmproxy to capture the request and see why it was failing, but it's something...right?


+1 Raises error on 3MB files

Pow 0.4.1
Rails 4
Ruby 2

mrhead commented Aug 20, 2013

Same for me, bigger files are failing, pow 0.4.1, rails 4, ruby 2.



Fails in Rails with Pow 0.4.1 using a <input type="file" multiple /> having files of total file size above 16MB. Didn't find anything in the configuration doc that specified I could increase the maximum upload size. Works perfectly when the total file size is below 16MB.

The request goes through, but all the submitted parameters are stripped and running params in a debug console shows only :action and :controller are left.

If I use thin there are no problems.



Seeing the same result as @theodorton.

mreinsch commented Sep 9, 2013

+1 - Rails 3.2.13, Rack 1.4.5, Pow 0.4.1

I actually only got an "obfuscated" version of the error:

TypeError - can't convert nil into Hash:
  rack (1.4.5) lib/rack/request.rb:221:in `merge'
  rack (1.4.5) lib/rack/request.rb:221:in `params'

I then spend quite some time digging into rack to finally figure out that it's throwing a "bad content body" in rack-1.4.5/lib/rack/multipart/parser.rb:130.

Switched to unicorn and all seems fine now.






No problem

On 17/10/2013, at 9:22 PM, Andrei Filimonov notifications@github.com wrote:


Reply to this email directly or view it on GitHub.

sookcha commented Nov 19, 2013








Definitely linked to file size.

xiaods commented Dec 8, 2013

+1 Definitely limited to file size.

walter commented Jan 3, 2014


Just experienced this as well. 15Mb file causes overall form to fails with "WARNING: Can't verify CSRF token authenticity" message.

Mac OS X 10.8.5, Safari 6.1, Carrierwave 0.9.0, Rails 3.2.16.

I confirmed that a 77Kb file works fine.

I also confirmed that the problem doesn't occur with webrick with the 15Mb file.



We're having the same problem, BUT: This happens after uploading a file, then right away uploading a second file. If we only try to upload one file (or if we wait long enough) everything works correctly. The file size is of 700kb.

So possibly not an issue on file size, but on the amount of memory used to process the files.


+1 (file size related as well)

firedev commented Feb 4, 2014

Is it Pow-specific? Or should I be careful pushing the same code to production as well?

chinito commented Feb 4, 2014

I had this error always when using pow. no problems, with thin or webrick or in production. That's why I don't use Pow anymore.

Emerson commented Feb 13, 2014

Having this problem as well!


Same here. Pow + Carrierwave

madrobby commented Mar 3, 2014

Same issue here, pow 0.4.1, Rails 2.3, REE 1.8.7. Small files work, larger file (this one has ~10MB).

/!\ FAILSAFE /!\  Mon Mar 03 11:47:12 -0500 2014
  Status: 500 Internal Server Error
  bad content body
    /Users/thomasfuchs/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/rack-1.1.6/lib/rack/utils.rb:530:in `parse_multipart'
    /Users/thomasfuchs/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/rack-1.1.6/lib/rack/request.rb:268:in `parse_multipart'
    /Users/thomasfuchs/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/rack-1.1.6/lib/rack/request.rb:146:in `POST'
    /Users/thomasfuchs/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/rack-1.1.6/lib/rack/methodoverride.rb:15:in `call'
xiaods commented Mar 4, 2014

Hi All, If we only report bug, not identify the root reason, we will can't get it resolved. anyone can help us and give some hints.

tomafro commented Mar 17, 2014

I can consistently reproduce this (or at least related) problems using pow with both rails and sinatra. A simple app showing this is here: https://github.com/tomafro/pow-large-upload-failure. It works using both rack and nack directly, but throws a NoMethodError caused by a 'missing' file.


For what it's worth, I put a bunch of debug logs into the Nack::Server code (which is where the Ruby process receives data from the nodejs HTTP server).

read_nonblock (https://github.com/josh/nack/blob/master/lib/nack/server.rb#L107) receives a blob of data looking like <HEADER_SIZE>:<HTTP_HEADER_AS_JSON>,<BODY_SIZE>:<HTTP_BODY>. The sizes and the header all look sane. However, the http body within that blob is not the start of the request body - it's taken from a ways into it. The size of the chunk that's missing appears to be fairly random, but I've seen values from 92kb - 800kb.

Weirdly, the actual start of the request body then appears mangled into the buffer that Nack::Server is piecing together. However the tail of the request body seems to reliably come at the end of the buffer. It kind of seems like the body chunks are getting received out of order.

tomafro commented Mar 17, 2014

@jdelStrother That's really useful, thanks. Looks like we'll need to look a little higher up the chain to see what's mangling the data.

tomafro commented Apr 2, 2014

d3f4836 should fix this data mangling bug


Outstanding, thanks. I just transferred a 50MB file with no problems, which I've never been able to do before on Pow.


This is awesome!

I understand that individual issues can't dictate new released, but I hope you can mint a new version soon :)

tomafro commented Apr 4, 2014

@sandstrom Freshly baked 0.4.3 release now available


@tomafro Awesome, thanks! ⛵️


Thanks for fixing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment