Skip to content

Conversation

@Maria-12648430
Copy link
Contributor

Currently, the spawn options monitor and {monitor, MonitorOpts} are disallowed in the proc_lib:start* functions. This goes back all the way to R11, a ticket OTP-6345, and this post on the old Erlang ML.

For proc_lib:start_monitor, it makes no sense to forbid monitor options. Or at least, we don't see any benefit in doing so. On the contrary, it prevents "customizing" the monitor (eg custom tags, usage of the new priority option, etc). This PR removes this restriction.

For proc_lib:start and proc_lib:start_link, it would be possible to remove the restriction also, that is, without restoring the buggy behavior that seems to have given raise to OTP-6345.
However, in the presence of a monitor or {monitor, MonitorOpts} spawn option, the return value would change from Ret to {Ret, Mon}, with repercussions via gen into the start/start_link functions of the gen_* behaviors.
This may be ok, and require mostly work on the specs and documentation in the gen_* behaviors, aside from some adaptions in gen. The bigger question IMO is if and how supervisors should cope with this?


This PR also does a few more things than what is listed above, which are related to the new {link, LinkOpts} spawn option that appeared with the new priority messages. Those are mostly just documentation changes.

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2025

CT Test Results

    4 files    221 suites   1h 55m 14s ⏱️
3 748 tests 3 644 ✅ 104 💤 0 ❌
4 795 runs  4 667 ✅ 128 💤 0 ❌

Results for commit d11e342.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@jhogberg jhogberg added the team:VM Assigned to OTP team VM label May 12, 2025
is_atom(F),
is_list(A) ->
?VERIFY_NO_MONITOR_OPT(M, F, A, Timeout, SpawnOpts),
SpawnOpts1 = ensure_spawn_option(monitor, SpawnOpts),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW using [monitor, monitor] or [monitor, {monitor, Opts}] is just fine in spawn_opt so it might be fine to just add this option unconditionally

Copy link
Contributor Author

@Maria-12648430 Maria-12648430 May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but which one of conflicting options (eg monitor vs {monitor, Opts}) wins is undocumented (currently, it is the last one in the list). So if we want to play strictly by the book ("what's not documented may change, at any time, without notice"), we need to check.

@Maria-12648430 Maria-12648430 force-pushed the allow_monitor_opts_in_proc_lib_start_monitor branch from 6d9d85b to bd983db Compare November 27, 2025 08:37
@Maria-12648430 Maria-12648430 force-pushed the allow_monitor_opts_in_proc_lib_start_monitor branch from a1761e9 to d11e342 Compare November 27, 2025 10:05
@Maria-12648430
Copy link
Contributor Author

The type erlang:link_option/0 was not exported, but should be (like, erlang:monitor_option/0 is also exported). On the way, I improved the documentation there a little.

@Maria-12648430
Copy link
Contributor Author

Btw @rickard-green @jhogberg this PR has been lying around for quite a while now, since May. Is there any interest in it?

@juhlig
Copy link
Contributor

juhlig commented Nov 27, 2025

For proc_lib:start and proc_lib:start_link, it would be possible to remove the restriction also, that is, without restoring the buggy behavior that seems to have given raise to OTP-6345.
However, in the presence of a monitor or {monitor, MonitorOpts} spawn option, the return value would change from Ret to {Ret, Mon}, with repercussions via gen into the start/start_link functions of the gen_* behaviors.
This may be ok, and require mostly work on the specs and documentation in the gen_* behaviors, aside from some adaptions in gen. The bigger question IMO is if and how supervisors should cope with this?

I don't think supervisors need to handle this. It is the responsibility of the child start function to return something that the supervisor can handle.

That said, the child start function is executed in the context of the supervisor process, so if it sets up a monitor there one way or other, all this leads to is that the supervisor receives an unexpected message when the child exits.

About allowing monitor options in proc_lib:start and proc_lib:start_link, my opinion is divided. OTOH, I would say that there shouldn't be any such restrictions unless necessary. OTOH, all combinations are already possible (with this PR, even customization of monitors): if you want an unlinked, unmonitored process, use start. If you want a linked, unmonitored process, use start_link. If you want an unlinked, monitored process, use start_monitor. If you want a linked, monitored process, use start_monitor with a link option 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants