Skip to content

Commit 0004afe

Browse files
authored
Merge pull request #115 from ferd/binary_memory_dead_proc_survival
Prevent crash when calling binary_memory on a dead process
2 parents 98d0c80 + e3e7289 commit 0004afe

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/recon.erl

+4-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ proc_info(Pid, List) when is_list(List) ->
240240
false ->
241241
erlang:process_info(Pid, List);
242242
true ->
243-
Res = erlang:process_info(Pid, replace(binary_memory, binary, List)),
244-
proc_fake(List, Res)
243+
case erlang:process_info(Pid, replace(binary_memory, binary, List)) of
244+
undefined -> undefined;
245+
Res when is_list(Res) -> proc_fake(List, Res)
246+
end
245247
end.
246248

247249
%% @private Replace keys around

test/recon_SUITE.erl

+8-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,14 @@ binary_memory(_Config) ->
315315
Res2 = recon:info(Pid2, [binary_memory, binary, binary_memory]),
316316
%% we expect everything to look as a single call to process_info/2
317317
[{binary,X}, {binary_memory,_}, {binary,X}] = Res1,
318-
[{binary_memory,Y}, {binary,_}, {binary_memory,Y}] = Res2.
318+
[{binary_memory,Y}, {binary,_}, {binary_memory,Y}] = Res2,
319+
%% make sure we deal with dead processes fine
320+
{Pid, Ref} = spawn_monitor(fun() -> ok end),
321+
receive
322+
{'DOWN', Ref, _, _, _} -> ok
323+
end,
324+
?assertEqual(undefined, recon:info(Pid, [binary_memory])),
325+
ok.
319326

320327
%% Just check that we get many schedulers and that the usage values are all
321328
%% between 0 and 1 inclusively. We don't care for edge cases like a

0 commit comments

Comments
 (0)