couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r775724 - in /couchdb/trunk: ./ etc/default/couchdb src/couchdb/couch_db.erl
Date Sun, 17 May 2009 17:51:42 GMT
Author: kocolosk
Date: Sun May 17 17:51:42 2009
New Revision: 775724

URL: http://svn.apache.org/viewvc?rev=775724&view=rev
Log:
work around ibrowse giving response chunks too many bytes. Thanks Antony.

Initially committed on the 0.9.x branch by accident in 775634.  We want to
include this in 0.9.1 anyway, though, so shouldn't ultimately be a problem.

Modified:
    couchdb/trunk/   (props changed)
    couchdb/trunk/etc/default/couchdb   (props changed)
    couchdb/trunk/src/couchdb/couch_db.erl

Propchange: couchdb/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun May 17 17:51:42 2009
@@ -1,2 +1,3 @@
+/couchdb/branches/0.9.x:775634
 /couchdb/branches/design_resources:751716-751803
 /couchdb/branches/form:729440-730015

Propchange: couchdb/trunk/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun May 17 17:51:42 2009
@@ -1,3 +1,4 @@
+/couchdb/branches/0.9.x/etc/default/couchdb:775634
 /couchdb/branches/design_resources/etc/default/couchdb:751716-751803
 /couchdb/branches/form/etc/default/couchdb:729440-730015
 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440

Modified: couchdb/trunk/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db.erl?rev=775724&r1=775723&r2=775724&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db.erl Sun May 17 17:51:42 2009
@@ -644,12 +644,24 @@
     {ok, SpAcc};
 write_streamed_attachment(Stream, F, LenLeft, nil) ->
     Bin = F(),
-    {ok, StreamPointer} = couch_stream:write(Stream, Bin),
-    write_streamed_attachment(Stream, F, LenLeft - size(Bin), StreamPointer);
+    TruncatedBin = check_bin_length(LenLeft, Bin),
+    {ok, SpAcc} = couch_stream:write(Stream, TruncatedBin),
+    write_streamed_attachment(Stream, F, LenLeft - size(TruncatedBin), SpAcc);
 write_streamed_attachment(Stream, F, LenLeft, SpAcc) ->
     Bin = F(),
-    {ok, _} = couch_stream:write(Stream, Bin),
-    write_streamed_attachment(Stream, F, LenLeft - size(Bin), SpAcc).
+    TruncatedBin = check_bin_length(LenLeft, Bin),
+    {ok, _} = couch_stream:write(Stream, TruncatedBin),
+    write_streamed_attachment(Stream, F, LenLeft - size(TruncatedBin), SpAcc).
+
+%% on rare occasions ibrowse seems to process a chunked response incorrectly
+%% and include an extra "\r" in the last chunk.  This code ensures that we 
+%% truncate the downloaed attachment at the length specified in the metadata.
+check_bin_length(LenLeft, Bin) when size(Bin) > LenLeft ->
+    <<ValidData:LenLeft/binary, Crap/binary>> = Bin,
+    ?LOG_ERROR("write_streamed_attachment has written too much expected: ~p" ++
+        " got: ~p tail: ~p", [LenLeft, size(Bin), Crap]),
+    ValidData;
+check_bin_length(_, Bin) -> Bin.
 
 enum_docs_since_reduce_to_count(Reds) ->
     couch_btree:final_reduce(



Mime
View raw message