[erlang-questions] late on_loads on init

Xavier Noria fxn@REDACTED
Mon Apr 9 14:25:57 CEST 2018


I have observed that on_load handlers happen late in the init process.

I would have expected that an on_load handler ran when the module is loaded
into the VM as primLoads are processed
<https://github.com/erlang/otp/blob/1c8187a1dd5b2c807caf73cc86657c5eae0f6569/erts/preloaded/src/init.erl#L895>
.

But, it turns out they do not run at that point. Before on load handlers
run, all applications are loaded, and kernel started. Only later does the
hook get executed, and boot continues starting the rest of applications.

In a production Distilley release for example (embedded mode, in
particular), this is easy to see passing ERL_OPTS=-init_debug to a command.
You'll see {`running_on_load_handler`, Module} printed when the hook is
invoked.

Two questions here:

1) Is this done because starting kernel is needed to have a minimum of
things setup in order to run code, do I/O etc. in the on_load handler? If
yes, is application:load/1 carefully written to not depend on such setup?
(since it runs before kernel starts).

2) On the other hand, if you load a module on demand in interactive mode,
the hook is executed right away. That says primLoad has to load modules in
a different way somehow. Do you know which is the difference?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180409/ea3f8840/attachment.htm>


More information about the erlang-questions mailing list