[erlang-questions] processes stuck in erlang:bif_return_trap/1

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Tue Sep 9 00:06:54 CEST 2014


On Mon, Sep 8, 2014 at 10:30 PM, <H.Li@REDACTED> wrote:

> I don't quite understand what erlang:bif_return_trap/1 does, and am
> confused why so many processes got stuck in this function.
>

It is a Red Herring(tm)[0].

Suppose the VM has to execute some BIF, link for example, for a process P.
In the course of linking P to another process, the VM will figure out it
needs to send a distributed message and that the distribution channel is
clogged up. So the VM suspends P until the link message has succeeded. The
problem now, is that we can't return to P, since it is suspended, and we
have a result from the link function we wish to tell P once it is
unsuspended. We can bump the reduction counter to 0, but this will still
have P execute until the next reduction counter bump, which is not what we
want.

This is where bif_return_trap/1 comes in. We mangle the state of P such
that when it unsuspends, it is executing bif_return_trap/1 and the value is
ready for returning. That is, we arrange it such that bif_return_trap/1 is
an immediate continuation of the program.

This is why it is a red herring. Some other function has executed and
mangled your current state. If distribution/ports are in play, consider
using erlang:system_monitor/2 to watch over the errornous state. There are
some old posts by Paul Davis and Scott L. Fritchie which could be somewhat
related:

http://erlang.org/pipermail/erlang-questions/2012-December/071157.html

[0] Ni! Ni! Ni! Ni! Ni!


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140909/2ed39c09/attachment.htm>


More information about the erlang-questions mailing list