Skip to content

Commit 559e1eb

Browse files
committed
Merge branch 'maint'
* maint: [erts] Fix monitor of time_offset co-created with alias
2 parents 2d871ab + 7dc715a commit 559e1eb

3 files changed

Lines changed: 94 additions & 14 deletions

File tree

erts/emulator/beam/erl_proc_sig_queue.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,11 +6532,6 @@ erts_proc_sig_handle_incoming(Process *c_p, erts_aint32_t *statep,
65326532
ASSERT(erts_monitor_is_origin(mon));
65336533
handle_persistent_mon_msg(c_p, &tracing, type, mon, sig,
65346534
msg, next_nm_sig);
6535-
6536-
if ((mon->flags & ERTS_ML_STATE_ALIAS_MASK)
6537-
== ERTS_ML_STATE_ALIAS_ONCE) {
6538-
mon->flags &= ~ERTS_ML_STATE_ALIAS_MASK;
6539-
}
65406535
}
65416536
else {
65426537
cnt++;

erts/emulator/beam/erl_time_sup.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ erts_demonitor_time_offset(ErtsMonitor *mon)
19931993
typedef struct {
19941994
Eterm pid;
19951995
Eterm ref;
1996-
Eterm heap[ERTS_REF_THING_SIZE];
1996+
Eterm heap[ERTS_PID_REF_THING_SIZE];
19971997
} ErtsTimeOffsetMonitorInfo;
19981998

19991999
typedef struct {
@@ -2007,7 +2007,7 @@ save_time_offset_monitor(ErtsMonitor *mon, void *vcntxt, Sint reds)
20072007
ErtsTimeOffsetMonitorContext *cntxt;
20082008
ErtsMonitorData *mdp = erts_monitor_to_data(mon);
20092009
Eterm *from_hp, *to_hp;
2010-
Uint mix;
2010+
Uint mix, sz;
20112011
int hix;
20122012

20132013
cntxt = (ErtsTimeOffsetMonitorContext *) vcntxt;
@@ -2016,11 +2016,13 @@ save_time_offset_monitor(ErtsMonitor *mon, void *vcntxt, Sint reds)
20162016
cntxt->to_mon_info[mix].pid = mon->other.item;
20172017
to_hp = &cntxt->to_mon_info[mix].heap[0];
20182018

2019-
ASSERT(is_internal_ordinary_ref(mdp->ref));
2019+
ASSERT(is_internal_ordinary_ref(mdp->ref)
2020+
|| is_internal_pid_ref(mdp->ref));
20202021
from_hp = internal_ref_val(mdp->ref);
2021-
ASSERT(thing_arityval(*from_hp) + 1 == ERTS_REF_THING_SIZE);
2022+
sz = thing_arityval(*from_hp) + 1;
2023+
ASSERT(sz <= ERTS_PID_REF_THING_SIZE);
20222024

2023-
for (hix = 0; hix < ERTS_REF_THING_SIZE; hix++)
2025+
for (hix = 0; hix < sz; hix++)
20242026
to_hp[hix] = from_hp[hix];
20252027

20262028
cntxt->to_mon_info[mix].ref
@@ -2073,15 +2075,14 @@ send_time_offset_changed_notifications(void *new_offsetp)
20732075

20742076
if (no_monitors) {
20752077
Eterm *hp, *patch_refp, new_offset_term, message_template;
2076-
Uint mix, hsz;
2078+
Uint mix, same_hsz;
20772079

20782080
/* Make message template */
20792081

20802082
hp = (Eterm *) (tmp + no_monitors*sizeof(ErtsTimeOffsetMonitorInfo));
20812083

2082-
hsz = 6; /* 5-tuple */
2083-
hsz += ERTS_REF_THING_SIZE;
2084-
hsz += ERTS_SINT64_HEAP_SIZE(new_offset);
2084+
same_hsz = 6; /* 5-tuple */
2085+
same_hsz += ERTS_SINT64_HEAP_SIZE(new_offset);
20852086

20862087
if (IS_SSMALL(new_offset))
20872088
new_offset_term = make_small(new_offset);
@@ -2098,6 +2099,10 @@ send_time_offset_changed_notifications(void *new_offsetp)
20982099
ASSERT(*patch_refp == THE_NON_VALUE);
20992100

21002101
for (mix = 0; mix < no_monitors; mix++) {
2102+
Uint hsz = same_hsz;
2103+
Eterm *ref_hp = internal_ref_val(to_mon_info[mix].ref);
2104+
hsz += thing_arityval(*ref_hp) + 1;
2105+
21012106
*patch_refp = to_mon_info[mix].ref;
21022107
erts_proc_sig_send_monitor_time_offset_msg(*patch_refp,
21032108
to_mon_info[mix].pid,

erts/emulator/test/process_SUITE.erl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
spawn_monitor_alias/1,
112112
demonitor_aliasmonitor/1,
113113
down_aliasmonitor/1,
114+
monitor_time_offset_alias/1,
114115
monitor_tag/1,
115116
no_pid_wrap/1,
116117
processes_iter/1]).
@@ -215,6 +216,7 @@ groups() ->
215216
{alias, [],
216217
[alias_bif, monitor_alias, spawn_monitor_alias,
217218
demonitor_aliasmonitor, down_aliasmonitor,
219+
monitor_time_offset_alias,
218220
dist_frag_alias, dist_frag_unaliased]}].
219221

220222
init_per_suite(Config) ->
@@ -5715,6 +5717,84 @@ down_aliasmonitor(Config) when is_list(Config) ->
57155717
peer:stop(Peer),
57165718
ok.
57175719

5720+
monitor_time_offset_alias(Config) when is_list(Config) ->
5721+
monitor_time_offset_alias_test(explicit_unalias),
5722+
monitor_time_offset_alias_test(demonitor),
5723+
monitor_time_offset_alias_test(reply_demonitor).
5724+
5725+
monitor_time_offset_alias_test(Deactivate) ->
5726+
Me = self(),
5727+
{ok, Peer, Node} = ?CT_PEER(#{args => ["+C", "single_time_warp"]}),
5728+
TrySelfAlias = fun (Alias) ->
5729+
Ref = make_ref(),
5730+
Alias ! Ref,
5731+
receive Ref -> active
5732+
after 0 -> inactive
5733+
end
5734+
end,
5735+
Tester = spawn_link(Node,
5736+
fun () ->
5737+
MonAlias = monitor(time_offset, clock_service,
5738+
[{alias, Deactivate}]),
5739+
Me ! {self(), mon_alias, MonAlias},
5740+
receive
5741+
{Me, finalize_time_offset} ->
5742+
ok
5743+
end,
5744+
preliminary = erlang:system_flag(time_offset, finalize),
5745+
receive
5746+
{'CHANGE', MonAlias, time_offset, clock_service, _} ->
5747+
ok
5748+
after
5749+
1000 ->
5750+
exit(missing_time_offset_change_message)
5751+
end,
5752+
Me ! {self(), finalized_time_offset},
5753+
receive
5754+
{Me, alias_message} ->
5755+
Me ! {self(), alias_message}
5756+
end,
5757+
case Deactivate of
5758+
explicit_unalias ->
5759+
active = TrySelfAlias(MonAlias),
5760+
unalias(MonAlias);
5761+
demonitor ->
5762+
active = TrySelfAlias(MonAlias),
5763+
demonitor(MonAlias);
5764+
reply_demonitor ->
5765+
ok
5766+
end,
5767+
inactive = TrySelfAlias(MonAlias),
5768+
receive
5769+
{Me, pid_message} ->
5770+
Me ! {self(), pid_message}
5771+
end
5772+
end),
5773+
Alias = receive
5774+
{Tester, mon_alias, MonAlias} ->
5775+
MonAlias
5776+
end,
5777+
Tester ! {self(), finalize_time_offset},
5778+
receive
5779+
{Tester, finalized_time_offset} ->
5780+
ok
5781+
end,
5782+
Alias ! {self(), alias_message},
5783+
Tester ! {self(), pid_message},
5784+
receive
5785+
{Tester, alias_message} ->
5786+
ok;
5787+
{Tester, pid_message} ->
5788+
ct:fail(alias_did_not_work)
5789+
end,
5790+
receive
5791+
{Tester, pid_message} ->
5792+
ok
5793+
end,
5794+
unlink(Tester),
5795+
peer:stop(Peer),
5796+
ok.
5797+
57185798
monitor_tag(Config) when is_list(Config) ->
57195799
%% Exit signals with immediate exit reasons are sent
57205800
%% in a different manner than compound exit reasons, and

0 commit comments

Comments
 (0)