From a14326a92817d5013c50887d52aaca10cf91d84d Mon Sep 17 00:00:00 2001 From: Robert Newson Date: Fri, 7 Jan 2011 16:46:27 +0000 Subject: 11589 - explictly close file descriptor in couch_file Adam discovered that explicitly calling file:close/1 on the file descriptor does not cause the node to become unresponsive and drop out of the ring. --- apps/couch/src/couch_file.erl | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'apps/couch/src/couch_file.erl') diff --git a/apps/couch/src/couch_file.erl b/apps/couch/src/couch_file.erl index b3d91bb4..285a04f2 100644 --- a/apps/couch/src/couch_file.erl +++ b/apps/couch/src/couch_file.erl @@ -158,18 +158,7 @@ sync(Fd) -> %% Returns: ok %%---------------------------------------------------------------------- close(Fd) -> - MRef = erlang:monitor(process, Fd), - try - catch unlink(Fd), - catch exit(Fd, shutdown), - receive - {'DOWN', MRef, _, _, _} -> - ok - end - after - erlang:demonitor(MRef, [flush]) - end. - + gen_server:call(Fd, close, infinity). delete(RootDir, Filepath) -> delete(RootDir, Filepath, true). @@ -289,9 +278,16 @@ maybe_track_open_os_files(FileOptions) -> couch_stats_collector:track_process_count({couchdb, open_os_files}) end. -terminate(_Reason, _Fd) -> - ok. +terminate(Reason, Fd) -> + case Reason of + normal -> + ok; + _ -> + file:close(Fd) + end. +handle_call(close, _From, #file{fd=Fd}=File) -> + {stop, normal, file:close(Fd), File}; handle_call({pread_iolist, Pos}, _From, File) -> {LenIolist, NextPos} = read_raw_iolist_int(File, Pos, 4), -- cgit v1.2.3