diff options
author | Robert Newson <robert.newson@cloudant.com> | 2011-01-07 17:22:15 +0000 |
---|---|---|
committer | Robert Newson <robert.newson@cloudant.com> | 2011-01-07 17:22:15 +0000 |
commit | a3b56d93aa76877a942e74cd25a9141b97be47c1 (patch) | |
tree | 79c6efa12e27b1590fb9bd26a1432e8193fad2a5 | |
parent | bdfa34375c93e94511700150d6db09ea85915ac5 (diff) |
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.
-rw-r--r-- | apps/couch/src/couch_file.erl | 21 |
1 files changed, 7 insertions, 14 deletions
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), |