Running Erlang on Android devices / issue on network change

Hello together,

i am using erlang on Android devices and currently i get some errors when the user on the device change its network.e.g. WiFi to off and mobile data on - then it take some times (e.g. 30-120 sec to realize that the erlang process is in this time not able to write to child process.

Maybe someone knows some hints or tips to that?

Log:
erts-13.2/bin/inet_gethost[28875]: WARNING:Unable to write to child process.

erts-13.2/bin/inet_gethost[28853]: WARNING:Timeout waiting for child process to die, ignoring child (pid = 127).

erts-13.2/bin/inet_gethost[28853]: WARNING:Unable to write to child process.

erts-13.2/bin/inet_gethost[28852]: WARNING:Timeout waiting for child process to die, ignoring child (pid = 28853).

2 Likes

I’ve been having a similar problem and for that wrote a socket watcher, that polls the network interfaces and then closes sockets when the interfaces change: https://github.com/diodechain/network_monitor (Elixir code, but you’ll get the concept)

That said your error messages about inet_gethost seem to indicate that the errors are happening during dns lookup vs. on the tcp socket. If that is indeed the case you could try experimenting with using edns within erlang instead of inet_gethost overall.

  1. Set the environment variable ERL_INETRC to the path & filename of your inetrc
export ERL_INETRC=inetrc
  1. Put this in your inetrc:
%% enable EDNS, 0 means enable YES!
{edns,0}.
{alt_nameserver, {8,8,8,8}}.
%% specify lookup method
{lookup, [dns]}.

This will circumvent using the Android systems DNS and instead use the Erlang provided implementation.