summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlang/OTP <otp@erlang.org>2023-04-20 14:11:13 +0200
committerErlang/OTP <otp@erlang.org>2023-04-20 14:11:13 +0200
commited28d17acc467330baa6a59c200fa678dd439943 (patch)
treeb1f2b4d15f7d4e9d6fcc41d6ff6709672a27dedf
parent04826f9a431760bdd05df4c6d427002fb7c38db3 (diff)
parent902d451bcdb745d250698015b70006ca28844dd1 (diff)
downloaderlang-ed28d17acc467330baa6a59c200fa678dd439943.tar.gz
Merge branch 'rickard/aliasmonitor-fix/24.3/OTP-18557' into maint-24
* rickard/aliasmonitor-fix/24.3/OTP-18557: [erts] Fix erroneous removal of alias from alias table
-rw-r--r--erts/emulator/beam/bif.c1
-rw-r--r--erts/emulator/beam/erl_bif_unique.c11
-rw-r--r--erts/emulator/beam/erl_proc_sig_queue.c1
-rw-r--r--erts/emulator/test/process_SUITE.erl50
4 files changed, 57 insertions, 6 deletions
diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c
index 3fc0267f99..e571068bd5 100644
--- a/erts/emulator/beam/bif.c
+++ b/erts/emulator/beam/bif.c
@@ -366,6 +366,7 @@ demonitor(Process *c_p, Eterm ref, Eterm *multip)
NIL,
THE_NON_VALUE);
amdp->origin.flags = mon->flags & ERTS_ML_STATE_ALIAS_MASK;
+ mon->flags &= ~ERTS_ML_STATE_ALIAS_MASK;
erts_monitor_tree_replace(&ERTS_P_MONITORS(c_p), mon, &amdp->origin);
break;
}
diff --git a/erts/emulator/beam/erl_bif_unique.c b/erts/emulator/beam/erl_bif_unique.c
index 7b3b3746b1..e1686c6f93 100644
--- a/erts/emulator/beam/erl_bif_unique.c
+++ b/erts/emulator/beam/erl_bif_unique.c
@@ -591,14 +591,15 @@ erts_pid_ref_delete(Eterm ref)
erts_rwmtx_rwlock(&tblp->rwmtx);
tep = hash_remove(&tblp->hash, &tmpl);
- ASSERT(tep);
erts_rwmtx_rwunlock(&tblp->rwmtx);
- if (tblp != &pid_ref_table[0].u.table)
- erts_free(ERTS_ALC_T_PREF_NSCHED_ENT, (void *) tep);
- else
- erts_free(ERTS_ALC_T_PREF_ENT, (void *) tep);
+ if (tep) {
+ if (tblp != &pid_ref_table[0].u.table)
+ erts_free(ERTS_ALC_T_PREF_NSCHED_ENT, (void *) tep);
+ else
+ erts_free(ERTS_ALC_T_PREF_ENT, (void *) tep);
+ }
}
}
diff --git a/erts/emulator/beam/erl_proc_sig_queue.c b/erts/emulator/beam/erl_proc_sig_queue.c
index 611563daea..ad37555ef5 100644
--- a/erts/emulator/beam/erl_proc_sig_queue.c
+++ b/erts/emulator/beam/erl_proc_sig_queue.c
@@ -5202,6 +5202,7 @@ erts_proc_sig_handle_incoming(Process *c_p, erts_aint32_t *statep,
mdp->ref, c_p->common.id,
NIL, NIL, THE_NON_VALUE);
amdp->origin.flags = ERTS_ML_STATE_ALIAS_UNALIAS;
+ omon->flags &= ~ERTS_ML_STATE_ALIAS_MASK;
erts_monitor_tree_replace(&ERTS_P_MONITORS(c_p),
omon,
&amdp->origin);
diff --git a/erts/emulator/test/process_SUITE.erl b/erts/emulator/test/process_SUITE.erl
index 81bc598a64..8dc2d8b7f0 100644
--- a/erts/emulator/test/process_SUITE.erl
+++ b/erts/emulator/test/process_SUITE.erl
@@ -87,6 +87,8 @@
monitor_alias/1,
spawn_monitor_alias/1,
alias_process_exit/1,
+ demonitor_aliasmonitor/1,
+ down_aliasmonitor/1,
monitor_tag/1]).
-export([prio_server/2, prio_client/2, init/1, handle_event/2]).
@@ -162,7 +164,8 @@ groups() ->
gc_request_when_gc_disabled, gc_request_blast_when_gc_disabled,
otp_16436, otp_16642]},
{alias, [],
- [alias_bif, monitor_alias, spawn_monitor_alias, alias_process_exit]}].
+ [alias_bif, monitor_alias, spawn_monitor_alias, alias_process_exit,
+ demonitor_aliasmonitor, down_aliasmonitor]}].
init_per_suite(Config) ->
A0 = case application:start(sasl) of
@@ -4692,6 +4695,51 @@ alias_process_exit(Config) when is_list(Config) ->
check_pid_ref_table_size(PRTSz),
ok.
+demonitor_aliasmonitor(Config) when is_list(Config) ->
+ {ok, Node} = start_node(Config),
+ Fun = fun () ->
+ receive
+ {alias, Alias} ->
+ Alias ! {alias_reply, Alias, self()}
+ end
+ end,
+ LPid = spawn(Fun),
+ RPid = spawn(Node, Fun),
+ AliasMonitor = erlang:monitor(process, LPid, [{alias, explicit_unalias}]),
+ erlang:demonitor(AliasMonitor),
+ LPid ! {alias, AliasMonitor},
+ receive {alias_reply, AliasMonitor, LPid} -> ok end,
+ %% Demonitor signal has been received and cleaned up. Cleanup of
+ %% it erroneously removed it from the alias table which caused
+ %% remote use of the alias to stop working...
+ RPid ! {alias, AliasMonitor},
+ receive {alias_reply, AliasMonitor, RPid} -> ok end,
+ exit(LPid, kill),
+ stop_node(Node),
+ false = is_process_alive(LPid),
+ ok.
+
+down_aliasmonitor(Config) when is_list(Config) ->
+ {ok, Node} = start_node(Config),
+ LPid = spawn(fun () -> receive infinty -> ok end end),
+ RPid = spawn(Node,
+ fun () ->
+ receive
+ {alias, Alias} ->
+ Alias ! {alias_reply, Alias, self()}
+ end
+ end),
+ AliasMonitor = erlang:monitor(process, LPid, [{alias, explicit_unalias}]),
+ exit(LPid, bye),
+ receive {'DOWN', AliasMonitor, process, LPid, bye} -> ok end,
+ %% Down signal has been received and cleaned up. Cleanup of
+ %% it erroneously removed it from the alias table which caused
+ %% remote use of the alias to stop working...
+ RPid ! {alias, AliasMonitor},
+ receive {alias_reply, AliasMonitor, RPid} -> ok end,
+ stop_node(Node),
+ ok.
+
monitor_tag(Config) when is_list(Config) ->
%% Exit signals with immediate exit reasons are sent
%% in a different manner than compound exit reasons, and