I want to delay the reply from my GenServer’s handle_call, so my handle_call looks like this:
def handle_call(:foo, from, state) do
{:noreply, [from | state]}
end
The problem is that when the time to reply to the client comes, the client (i.e. the ref from) could have been dead. So how can I check if it is alive?
Even checking beforehand is prone to a race condition where it dies after the check but before the message being sent back, so you can just not check as well, unless there‘s some benefit to the server by not sending the response.
@LostKobrakai is just noting that this is not something that can be guaranteed. If guarantee of reply is required then some other mechanism (a durable message queue for example) might be required.
This has the same problem as well. You might check what the first living process is and at the time you actually send the message it’s no longer alive and nobody receives the message.