2 ms·
If you do gen_X:call and the timeout expires before you receive a response, you may still get a response later (late reply). The timeout case can happen without
by toast0 6y ago
If you do gen_X:call and the timeout expires before you receive a response, you may still get a response later (late reply). The timeout case can happen without a connection loss or even without distribution. I believe gen_X:call sets a monitor (maybe a link?) though, so if the server process is distributed, and the connection is lost, the call will fail; however, the server does not set a monitor on the client (to my knowledge), so when it finishes processing the message, it will reply to the client; distribution may have already reconnected, or sending the reply may cause a reconnection. I don't have great knowledge on the monitor, where I worked, we used a modified call that didn't set monitors, because it was too much overhead; we relied on timeouts instead.
If the call was part of a library function, you can return {error, timeout} or whatever, but the process you ran in will have that reply message in its mailbox, possibly forever if it only does selective receives. This will show up in your system as growing memory use, and slowing message processing (unless all of your messaging is selective receives with new references that benefits from the mailbox marking optimization).
In the proxy process alternative, you would spawn a new process to do the gen_X:call, and message back to the real client process. Any late replies get discarded as the spawned process will be dead. But spawning a process isn't free, even if an Erlang process is much lower cost than an OS thread or process. Without looking at details of the implementation, using a process alias seems like a reasonable optimization.