From bbca687b8ce0c0cbf10407f2aaf87e18bfc311e5 Mon Sep 17 00:00:00 2001 From: Andrey Stikheev Date: Sun, 25 Oct 2009 13:11:35 +0300 Subject: workaround FreeBSD/OSX IO bug for large uploads Under FreeBSD writing to the file in sync mode does not change current position, so change position to the end of the file. Without this patch multipart post requests with large data (image uploading) does not work correctly: Status: 500 Internal Server Error bad content body /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:347:in `parse_multipart' /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:319:in `loop' /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:319:in `parse_multipart' File position behavior under FreeBSD : ruby -v ruby 1.8.7 (2009-04-08 patchlevel 160) [i386-freebsd7] irb(main):001:0> b = File.new("abc", "w+") => # irb(main):002:0> b.sync = true => true irb(main):004:0> b.write("abc") => 3 irb(main):005:0> b.pos => 0 Acked-by: Eric Wong --- lib/unicorn/tee_input.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index 188e2ea..7e77cdf 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -131,6 +131,7 @@ module Unicorn begin if parser.filter_body(dst, socket.readpartial(length, buf)).nil? @tmp.write(dst) + @tmp.seek(0, IO::SEEK_END) # workaround FreeBSD/OSX + MRI 1.8.x bug return dst end rescue EOFError -- cgit v1.2.3-24-ge0c7