about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-05-11 22:40:37 -0700
committerEric Wong <normalperson@yhbt.net>2009-05-11 22:40:37 -0700
commitb3c6fdce2a03da3d335315f18c19669a259824c5 (patch)
tree0b228a7247452da6f2ee1fa257451cf1278c6101
parent925f88873fac6541f5521a5dacfc8f1b3a91712c (diff)
downloadunicorn-b3c6fdce2a03da3d335315f18c19669a259824c5.tar.gz
If we're using middleware that pushes the body into an
array, bad things will happen if we're clobbering the
string for each iteration of body#each.
-rw-r--r--lib/unicorn/app/exec_cgi.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb
index 2c71df9..8f81d78 100644
--- a/lib/unicorn/app/exec_cgi.rb
+++ b/lib/unicorn/app/exec_cgi.rb
@@ -95,11 +95,15 @@ module Unicorn::App
       # Allows +out+ to be used as a Rack body.
       def out.each
         sysseek(@unicorn_app_exec_cgi_offset)
-        buf = ''
+
+        # don't use a preallocated buffer for sysread since we can't
+        # guarantee an actual socket is consuming the yielded string
+        # (or if somebody is pushing to an array for eventual concatenation
         begin
-          loop { yield(sysread(CHUNK_SIZE, buf)) }
+          yield(sysread(CHUNK_SIZE))
         rescue EOFError
-        end
+          return
+        end while true
       end
 
       prev = nil