diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c index a618dead7d1e..230e4437cfd6 100644 --- a/erts/emulator/beam/erl_process.c +++ b/erts/emulator/beam/erl_process.c @@ -13692,7 +13692,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: diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c index fb7fe70dfe45..772c0eb3e13d 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c +++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c @@ -2949,6 +2949,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[])