Skip to content

Commit

Permalink
kernel: Fix group to not crash if group_history fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
garazdawi committed Apr 25, 2024
1 parent 5484a04 commit 88d77ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/kernel/src/group.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
%%
-module(group).

-include_lib("kernel/include/logger.hrl").

%% A group leader process for user io.
%% This process receives input data from user_drv in this format
%% {Drv,{data,unicode:charlist()}}
Expand Down Expand Up @@ -1005,7 +1007,12 @@ save_line_buffer("\n", Lines) ->
save_line_buffer(Line, [Line|_Lines]=Lines) ->
save_line_buffer(Lines);
save_line_buffer(Line, Lines) ->
group_history:add(Line),
try
group_history:add(Line)
catch E:R:ST ->
?LOG_ERROR(#{ msg => "Failed to write to shell history",
error => {E, R, ST} })
end,
save_line_buffer([Line|Lines]).

save_line_buffer(Lines) ->
Expand Down
5 changes: 4 additions & 1 deletion lib/kernel/src/group_history.erl
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ find_path() ->
to_drop() ->
case application:get_env(kernel, shell_history_drop) of
undefined ->
application:set_env(kernel, shell_history_drop, ?DEFAULT_DROP),
%% The AC might be overloaded/not responding and
%% we want the shell to be as responsive as possible
%% so we set a short timeout
application:set_env(kernel, shell_history_drop, ?DEFAULT_DROP, 10),
?DEFAULT_DROP;
{ok, V} when is_list(V) -> [Ln++"\n" || Ln <- V];
{ok, _} -> ?DEFAULT_DROP
Expand Down

0 comments on commit 88d77ed

Please sign in to comment.