[erlang-questions] High Priority processes not handling system tasks

Maxim Fedorov dane@REDACTED
Sat May 26 04:35:34 CEST 2018


G’Day,
Below is a chunk of code that does not look bad at a first glance, but…


start() ->
    Pid = spawn(?MODULE, high, []),
    io:format("Starting... "),
    erlang:check_process_code(Pid, rec),
    io:format("collected~n").

high() ->
    erlang:process_flag(priority, high),
    endless(10).

endless(X) ->
    endless(X+1).


start() never returns, because check_process_code schedules a normal priority system task against high priority process. It seems to be logical, but leads to some really weird effects. For example, code:soft_purge() hangs (in erts_code_purger, cpc_receive), thus whole code_server gen_server hangs, and this paralyses almost everything (a separate issue - cpc_receive has no receive timeout at all, possibly stalling whole VM).

Is it designed behaviour? I have quite a straightforward solution (patch for erl_process.c), but I might now understand consequences. 
Applies to R19+ (with 'new purge strategy' enabled). Older releases (eg. R16B) are not affected.

Regards,
  Maxim Fedorov



More information about the erlang-questions mailing list