diff options
author | John Högberg <[email protected]> | 2018-11-16 09:52:39 +0100 |
---|---|---|
committer | John Högberg <[email protected]> | 2018-11-16 09:52:39 +0100 |
commit | 200c2718e16c9186f3b4cdccaf989a31946a3f20 (patch) | |
tree | ca57a19b37349a6d5aa742c38bf5d87147340b0c /erts/preloaded | |
parent | cf8aae2646bc0c200d44577ca2942d3b53bd30e9 (diff) | |
parent | 7c902ed60b759c30aabfecde52baa2d12b8885bd (diff) | |
download | otp-200c2718e16c9186f3b4cdccaf989a31946a3f20.tar.gz otp-200c2718e16c9186f3b4cdccaf989a31946a3f20.tar.bz2 otp-200c2718e16c9186f3b4cdccaf989a31946a3f20.zip |
Merge branch 'john/erts/defer-orphan-file-close/OTP-15421/ERIERL-261' into maint
* john/erts/defer-orphan-file-close/OTP-15421/ERIERL-261:
Fix broken assertion on monitor release
Avoid closing files in gc/monitor callbacks
Diffstat (limited to 'erts/preloaded')
-rw-r--r-- | erts/preloaded/ebin/prim_file.beam | bin | 27780 -> 28528 bytes | |||
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 18 |
2 files changed, 17 insertions, 1 deletions
diff --git a/erts/preloaded/ebin/prim_file.beam b/erts/preloaded/ebin/prim_file.beam Binary files differindex df611f2bb0..d0435a10ef 100644 --- a/erts/preloaded/ebin/prim_file.beam +++ b/erts/preloaded/ebin/prim_file.beam diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index 6d85868183..5fc22bc582 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -83,6 +83,15 @@ internal_normalize_utf8(_) -> is_translatable(_) -> erlang:nif_error(undefined). +%% This is a janitor process used to close files whose controlling process has +%% died. The emulator will be torn down if this is killed. +delayed_close_loop() -> + receive + {close, FRef} when is_reference(FRef) -> delayed_close_nif(FRef); + _ -> ok + end, + delayed_close_loop(). + %% %% Returns {error, Reason} | {ok, BytesCopied} @@ -95,7 +104,12 @@ copy(#file_descriptor{module = ?MODULE} = Source, file:copy_opened(Source, Dest, Length). on_load() -> - ok = erlang:load_nif(atom_to_list(?MODULE), 0). + Pid = spawn(fun() -> + process_flag(trap_exit, true), + delayed_close_loop() + end), + true = register(erts_prim_file, Pid), + ok = erlang:load_nif(atom_to_list(?MODULE), Pid). open(Name, Modes) -> %% The try/catch pattern seen here is used throughout the file to adhere to @@ -482,6 +496,8 @@ truncate_nif(_FileRef) -> erlang:nif_error(undef). get_handle_nif(_FileRef) -> erlang:nif_error(undef). +delayed_close_nif(_FileRef) -> + erlang:nif_error(undef). %% %% Quality-of-life helpers |