summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_doc.erl
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-06-12 16:16:29 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-06-12 16:16:29 +0000
commitd5da180b06b8711c72bf38e35c380a25804e018f (patch)
tree35ec19aca1862411a5a330b311eca0c8d276a046 /src/couchdb/couch_doc.erl
parente192fe836b55d7e58273554a3a739218bd78798e (diff)
Backport revision 1129897 from trunk
Fixes to the doc PUT multipart API Don't hold the connection forever if the document is rejected by a validate_doc_update function. The solution is to discard all the attachments' data if the document was rejected. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1134942 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_doc.erl')
-rw-r--r--src/couchdb/couch_doc.erl19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl
index 5cd6ac80..531eb6bb 100644
--- a/src/couchdb/couch_doc.erl
+++ b/src/couchdb/couch_doc.erl
@@ -18,6 +18,7 @@
-export([validate_docid/1]).
-export([doc_from_multi_part_stream/2]).
-export([doc_to_multi_part_stream/5, len_doc_to_multi_part_stream/4]).
+-export([abort_multi_part_stream/1]).
-include("couch_db.hrl").
@@ -501,7 +502,7 @@ doc_from_multi_part_stream(ContentType, DataFun) ->
receive {Parser, finished} -> ok end,
erlang:put(mochiweb_request_recv, true)
end,
- {ok, Doc#doc{atts=Atts2}, WaitFun}
+ {ok, Doc#doc{atts=Atts2}, WaitFun, Parser}
end.
mp_parse_doc({headers, H}, []) ->
@@ -542,3 +543,19 @@ mp_parse_atts(body_end) ->
end.
+abort_multi_part_stream(Parser) ->
+ abort_multi_part_stream(Parser, erlang:monitor(process, Parser)).
+
+abort_multi_part_stream(Parser, MonRef) ->
+ case is_process_alive(Parser) of
+ true ->
+ Parser ! {get_bytes, self()},
+ receive
+ {bytes, _Bytes} ->
+ abort_multi_part_stream(Parser, MonRef);
+ {'DOWN', MonRef, _, _, _} ->
+ ok
+ end;
+ false ->
+ erlang:demonitor(MonRef, [flush])
+ end.