Mediocre Gopher
Mediocre Gopher

Reputation: 2304

Erlang hot reloading and badfuns

I have a set up where I have four instances of a server running, two instances per server box. My server involves lots of passing around anonymous functions and running them on a different thread (which is probably on a different server).

Today I did a code reload which involved changing the contents of some static functions on one of the instances (planning on doing each instance sequentially). Upon running my reload I was greeted with an avalanche of badfun errors. The other instance on that box also began spewing out similar errors. The two instances on the other box we seemingly unaffected.

I found this article: http://www.javalimit.com/2010/05/passing-funs-to-other-erlang-nodes.html which seems to imply that the reason for these errors is that the anonymous functions had different versions between the two nodes and therefore it broke. However, in testing I can't reproduce this error. Also I've reloaded code many times before without seeing anything like this. This is, however, the first time I've reloaded with two instances per box (previously it was one instance per box). Does anyone have any insights into why this happened, and maybe how to prevent it (without killing everything and restarting it, which is what I had to do).

Upvotes: 5

Views: 461

Answers (1)

Lukas
Lukas

Reputation: 5327

In order to identify funs the erlang vm hashes the code and incorporates that has in the fun identifier. It is this identifier which is sent to the other node and when trying to access that fun on the remote side it cannot find a fun with that hash.

To see this in action take a piece of code with an anonymous fun and load it into one vm, then edit the fun and load the new code onto a separate vm. Then try to send the original fun to the second vm and execute it.

Upvotes: 3

Related Questions