You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by mi...@apache.org on 2014/10/08 13:10:51 UTC
[1/2] couch commit: updated
refs/heads/2365-fix-failed-multipart-process-leak to fd7f888
Repository: couchdb-couch
Updated Branches:
refs/heads/2365-fix-failed-multipart-process-leak [created] fd7f88895
[squash] Add a test for COUCHDB-2365
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/8f9bd3e6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/8f9bd3e6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/8f9bd3e6
Branch: refs/heads/2365-fix-failed-multipart-process-leak
Commit: 8f9bd3e6c762b58a2d7d3bdc06131a606d904783
Parents: 46cb6a4
Author: Mike Wallace <mi...@apache.org>
Authored: Tue Oct 7 23:45:11 2014 +0100
Committer: Mike Wallace <mi...@apache.org>
Committed: Wed Oct 8 10:01:44 2014 +0100
----------------------------------------------------------------------
test/couch_stream_tests.erl | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/8f9bd3e6/test/couch_stream_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stream_tests.erl b/test/couch_stream_tests.erl
index 3e84ca0..e12e714 100644
--- a/test/couch_stream_tests.erl
+++ b/test/couch_stream_tests.erl
@@ -38,7 +38,8 @@ stream_test_() ->
fun should_return_stream_size_on_close/1,
fun should_return_valid_pointers/1,
fun should_recall_last_pointer_position/1,
- fun should_stream_more_with_4K_chunk_size/1
+ fun should_stream_more_with_4K_chunk_size/1,
+ fun should_stop_on_normal_exit_of_stream_opener/1
]
}
}.
@@ -94,6 +95,21 @@ should_stream_more_with_4K_chunk_size({Fd, _}) ->
?_assertMatch({[{0, 4100}, {4106, 1020}], 5120, _, _, _},
couch_stream:close(Stream)).
+should_stop_on_normal_exit_of_stream_opener({Fd, _}) ->
+ RunnerPid = self(),
+ OpenerPid = spawn(
+ fun() ->
+ {ok, StreamPid} = couch_stream:open(Fd),
+ RunnerPid ! {pid, StreamPid}
+ end),
+ StreamPid = receive
+ {pid, StreamPid0} -> StreamPid0
+ end,
+ % Confirm the validity of the test by verifying the stream opener has died
+ ?_assertNot(is_process_alive(OpenerPid)),
+ % Verify the stream itself has also died
+ ?_assertNot(is_process_alive(StreamPid)).
+
read_all(Fd, PosList) ->
Data = couch_stream:foldl(Fd, PosList, fun(Bin, Acc) -> [Bin, Acc] end, []),
[2/2] couch commit: updated
refs/heads/2365-fix-failed-multipart-process-leak to fd7f888
Posted by mi...@apache.org.
Make couch_stream monitor the stream opener
This commit fixes a process leak which would happen when a process
opened a couch_stream and exited with reason normal before closing
the stream.
This patch makes the couch_stream gen_server monitor the process
which opens the stream. When that monitor sends an exit signal
the couch_stream gen_server is stopped and the process dies.
Closes COUCHDB-2365
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/fd7f8889
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/fd7f8889
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/fd7f8889
Branch: refs/heads/2365-fix-failed-multipart-process-leak
Commit: fd7f88895240b6fb5f8672ab48d8d18655803ee9
Parents: 8f9bd3e
Author: Mike Wallace <mi...@apache.org>
Authored: Tue Oct 7 17:09:34 2014 +0100
Committer: Mike Wallace <mi...@apache.org>
Committed: Wed Oct 8 10:23:49 2014 +0100
----------------------------------------------------------------------
src/couch_stream.erl | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/fd7f8889/src/couch_stream.erl
----------------------------------------------------------------------
diff --git a/src/couch_stream.erl b/src/couch_stream.erl
index e71542c..6877f0f 100644
--- a/src/couch_stream.erl
+++ b/src/couch_stream.erl
@@ -29,6 +29,7 @@
-record(stream,
{fd = 0,
+ opener_monitor,
written_pointers=[],
buffer_list = [],
buffer_len = 0,
@@ -50,7 +51,7 @@ open(Fd) ->
open(Fd, []).
open(Fd, Options) ->
- gen_server:start_link(couch_stream, {Fd, Options}, []).
+ gen_server:start_link(couch_stream, {Fd, self(), Options}, []).
close(Pid) ->
gen_server:call(Pid, close, infinity).
@@ -197,7 +198,7 @@ write(Pid, Bin) ->
gen_server:call(Pid, {write, Bin}, infinity).
-init({Fd, Options}) ->
+init({Fd, OpenerPid, Options}) ->
{EncodingFun, EndEncodingFun} =
case couch_util:get_value(encoding, Options, identity) of
identity ->
@@ -207,6 +208,7 @@ init({Fd, Options}) ->
end,
{ok, #stream{
fd=Fd,
+ opener_monitor=erlang:monitor(process, OpenerPid),
md5=couch_util:md5_init(),
identity_md5=couch_util:md5_init(),
encoding_fun=EncodingFun,
@@ -266,6 +268,7 @@ handle_call({write, Bin}, _From, Stream) ->
handle_call(close, _From, Stream) ->
#stream{
fd = Fd,
+ opener_monitor = MonRef,
written_len = WrittenLen,
written_pointers = Written,
buffer_list = Buffer,
@@ -288,6 +291,7 @@ handle_call(close, _From, Stream) ->
StreamLen = WrittenLen + iolist_size(WriteBin2),
{StreamInfo, StreamLen, IdenLen, Md5Final, IdenMd5Final}
end,
+ erlang:demonitor(MonRef),
{stop, normal, Result, Stream}.
handle_cast(_Msg, State) ->
@@ -296,5 +300,7 @@ handle_cast(_Msg, State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+handle_info({'DOWN', Ref, _, _, _}, #stream{opener_monitor=Ref} = State) ->
+ {stop, normal, State};
handle_info(_Info, State) ->
{noreply, State}.