summaryrefslogtreecommitdiff
path: root/apps/couch/src
diff options
context:
space:
mode:
authorRobert Newson <robert.newson@cloudant.com>2011-01-07 16:46:27 +0000
committerRobert Newson <robert.newson@cloudant.com>2011-01-07 16:46:40 +0000
commita14326a92817d5013c50887d52aaca10cf91d84d (patch)
treea44d894948e2b0fd67db7374b9d0ef5618dd0da0 /apps/couch/src
parenta5db6a8aedaf3e696b463023f2c6f7acf5ac5b57 (diff)
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.
Diffstat (limited to 'apps/couch/src')
-rw-r--r--apps/couch/src/couch_file.erl24
1 files changed, 10 insertions, 14 deletions
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),