Search code examples
ruby-on-railsnginxunicornunix-socketrainbows

104: Connection reset by peer: nginx + rainbows + over 1 mb uploads


I am running ThreadPool rainbows + nginx (unix socket)

On large file uploads I am getting the following in nginx error log (nothing in the application log):

readv() failed (104: Connection reset by peer) while reading upstream

The browser receives response:

413 Request Entity Too Large

Why does this happen?

  • "client_max_body_size 80M;" is set both on http and server level (just in case) in nginx
  • nginx communicates with rainbows over a unix socket (upstream socket + location @ proxy_pass)
  • I don't see anything in the other logs. I have checked:
    • rainbows log
    • foreman log
    • application log
    • dmesg and /var/log/messages
  • This happens when uploading a file ~> 1 MB size

Solution

  • Turns out Rainbows had a configuration option called client_max_body_size that defaulted to 1 MB The option is documented here

    If this options is on, Rainbows will 413 to large requests silently. You might not know it's breaking unless you run something in front of it.

    Rainbows! do
      # let nginx handle max body size
      client_max_body_size nil 
    end