diff options
author | Damien F. Katz <damien@apache.org> | 2010-03-04 01:09:22 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2010-03-04 01:09:22 +0000 |
commit | 3a3a9c1efab1c9fe4cd5ebb6c80da4005eb0806b (patch) | |
tree | f850ff24c113465531aab2bdcdb2f2e70855d00c /src/couchdb/couch_file.erl | |
parent | 2ea7ab6a8525184ecdbfcee69667e200511b9f9b (diff) |
Changed process tree shutdown to be synchronous, to eliminate spurious test failures caused by processes not shutdown fast enough or at the wrong time.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@918805 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r-- | src/couchdb/couch_file.erl | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index 5904260c..4c6928a7 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -176,13 +176,21 @@ sync(Fd) -> gen_server:call(Fd, sync, infinity). %%---------------------------------------------------------------------- -%% Purpose: Close the file. Is performed asynchronously. +%% Purpose: Close the file. %% Returns: ok %%---------------------------------------------------------------------- close(Fd) -> - Result = gen_server:cast(Fd, close), - catch unlink(Fd), - Result. + MRef = erlang:monitor(process, Fd), + try + catch unlink(Fd), + catch exit(Fd, shutdown), + receive + {'DOWN', MRef, _, _, _} -> + ok + end + after + erlang:demonitor(MRef, [flush]) + end. % 09 UPGRADE CODE old_pread(Fd, Pos, Len) -> @@ -219,6 +227,7 @@ init_status_error(ReturnPid, Ref, Error) -> % server functions init({Filepath, Options, ReturnPid, Ref}) -> + process_flag(trap_exit, true), case lists:member(create, Options) of true -> filelib:ensure_dir(Filepath), @@ -432,6 +441,8 @@ handle_cast(close, Fd) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. +handle_info({'EXIT', _, normal}, Fd) -> + {noreply, Fd}; handle_info({'EXIT', _, Reason}, Fd) -> {stop, Reason, Fd}. |