Assume that we want to hot-reload a gen_server module, with changes to the internal state.
So the appup will contain this instruction: {update, ch3, {advanced, []}}
As I understand it, during hot code loading release handler will perform the following steps:
- Traverse the supervision tree and collect all the processes that use the module ch3.
- Suspend all these processes using
sys:suspend
. - Load the new module version.
- Call
code_change
callback on all processes. - Resume the processes using
sys:resume
.
However, it looks like this will run into a problem if a new process with this module is started during step 1 or step 2. For example:
- We traverse the supervision tree and collect pids.
- New process is started with the old version of the module (say PID <0.1234.0>). This process is not included in the list of processes to update.
- Release handler suspends the processes in the list, loads the new module version, runs the code change and resumes.
- But that <0.1234.0> process is not included, and so it will crash when old module version is purged.
How is this situation handled? Is there something that release handler does to prevent it, or are these straggling processes simply left to crash and restart the usual way?