Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential lock order conflict in NIF monitor down callbacks #9008

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions erts/emulator/beam/erl_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -13483,7 +13483,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
Loading