Friday, September 12, 2008

Hot code swapping - take 2

This is a follow up on my previous article, in which I described a few problems with hot code swapping in Erlang

In a comment, Philip Robinson wrote:
It sounds like you have another (lost?) process running code from that module, running version 1, that never receives the switch_code message.
And that was exactly the cause of my problem. We were having a process leakage. The switch_code message was only sent to processes that we were tracking, not all processes belonging to the loaded module. Unfortunately, we were not careful enough and some of these processes were lost in the process of switching code, preventing future code swapping.

So we have no need for an after clause anymore. And I think that if you need such a hack, then you may not be properly managing your processes. At least, send the switch_code message to all the processes for a given module:


  lists:foreach(fun(Pid) <- Pid ! switch_code end,
[Pid || Pid <- processes(), erlang:check_process_code(Pid, Module)])

0 comments: