Skip to content

Commit

Permalink
Merge branch 'sverker/erts/nif-monitor-down-lock-conflict/erlangGH-8983
Browse files Browse the repository at this point in the history
…/OTP-19330' into maint-25

* sverker/erts/nif-monitor-down-lock-conflict/erlangGH-8983/OTP-19330:
  erts: Fix potential lock order conflict in NIF monitor down callbacks
  • Loading branch information
Erlang/OTP committed Nov 13, 2024
2 parents dd606e6 + 520edad commit 49abab4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions erts/emulator/beam/erl_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -13590,7 +13590,9 @@ erts_proc_exit_handle_monitor(ErtsMonitor *mon, void *vctxt, Sint reds)
break;
}
case ERTS_MON_TYPE_RESOURCE:
erts_proc_unlock(c_p, ERTS_PROC_LOCK_MAIN);
erts_fire_nif_monitor(mon);
erts_proc_lock(c_p, ERTS_PROC_LOCK_MAIN);
mon = NULL;
break;
case ERTS_MON_TYPE_DIST_PORT:
Expand Down
10 changes: 10 additions & 0 deletions erts/emulator/test/nif_SUITE_data/nif_SUITE.c
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,16 @@ static void monitor_resource_down(ErlNifEnv* env, void* obj, ErlNifPid* pid,
enif_send(env, &rsrc->receiver, msg_env, msg);
if (msg_env)
enif_free_env(msg_env);

/* OTP-19330 GH-8983:
* Verify calling enif_whereis_pid/port in down callback
* without lock order violation. */
{
ErlNifPid pid;
ErlNifPid port;
enif_whereis_pid(env, atom_null, &pid);
enif_whereis_port(env, atom_null, &port);
}
}

static ERL_NIF_TERM alloc_monitor_resource_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
Expand Down

0 comments on commit 49abab4

Please sign in to comment.