From b3c6fdce2a03da3d335315f18c19669a259824c5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 11 May 2009 22:40:37 -0700 Subject: exec_cgi: don't assume the body#each consumer is a socket 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. --- lib/unicorn/app/exec_cgi.rb | 10 +++++++--- 1 file 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 -- cgit v1.2.3-24-ge0c7