From a3b56d93aa76877a942e74cd25a9141b97be47c1 Mon Sep 17 00:00:00 2001 From: Robert Newson Date: Fri, 7 Jan 2011 17:22:15 +0000 Subject: BugzID: 11589 call file:close explicitly to keep VM responsive Deleting a large file in the previous scheme has caused the Erlang VM to become unresponsive (including making it drop out of the ring of nodes). The cause of this is currently unknown but Adam discovered that explicitly calling file:close/1 on the file descriptor does not cause this behavior. Accordingly, I have typed in his suggested fix and tested it. --- apps/couch/src/couch_file.erl | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'apps/couch/src') diff --git a/apps/couch/src/couch_file.erl b/apps/couch/src/couch_file.erl index b3d91bb4..a8a465af 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,13 @@ maybe_track_open_os_files(FileOptions) -> couch_stats_collector:track_process_count({couchdb, open_os_files}) end. -terminate(_Reason, _Fd) -> - ok. +terminate(_Reason, #file{fd = nil}) -> + ok; +terminate(_Reason, #file{fd = Fd}) -> + file:close(Fd). +handle_call(close, _From, #file{fd=Fd}=File) -> + {stop, normal, file:close(Fd), File#file{fd = nil}}; handle_call({pread_iolist, Pos}, _From, File) -> {LenIolist, NextPos} = read_raw_iolist_int(File, Pos, 4), -- cgit v1.2.3