Skip to content

Commit 172a15c

Browse files
committed
kernel: Fix group to not crash if group_history fails
There used to be a bug where the AC would block and set_env would crash. This caused the shell to be unuseable as it crashed all the time. So we add some safe guards to make sure that does not happen again.
1 parent ec8e440 commit 172a15c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/kernel/src/group.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
%%
2020
-module(group).
2121

22+
-include_lib("kernel/include/logger.hrl").
23+
2224
%% A group leader process for user io.
2325
%% This process receives input data from user_drv in this format
2426
%% {Drv,{data,unicode:charlist()}}
@@ -1005,7 +1007,12 @@ save_line_buffer("\n", Lines) ->
10051007
save_line_buffer(Line, [Line|_Lines]=Lines) ->
10061008
save_line_buffer(Lines);
10071009
save_line_buffer(Line, Lines) ->
1008-
group_history:add(Line),
1010+
try
1011+
group_history:add(Line)
1012+
catch E:R:ST ->
1013+
?LOG_ERROR(#{ msg => "Failed to write to shell history",
1014+
error => {E, R, ST} })
1015+
end,
10091016
save_line_buffer([Line|Lines]).
10101017

10111018
save_line_buffer(Lines) ->

lib/kernel/src/group_history.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ find_path() ->
374374
to_drop() ->
375375
case application:get_env(kernel, shell_history_drop) of
376376
undefined ->
377-
application:set_env(kernel, shell_history_drop, ?DEFAULT_DROP),
377+
%% The AC might be overloaded/not responding and
378+
%% we want the shell to be as responsive as possible
379+
%% so we set a short timeout
380+
application:set_env(kernel, shell_history_drop, ?DEFAULT_DROP, [{timeout, 10}]),
378381
?DEFAULT_DROP;
379382
{ok, V} when is_list(V) -> [Ln++"\n" || Ln <- V];
380383
{ok, _} -> ?DEFAULT_DROP

0 commit comments

Comments
 (0)