reading the section about “IO and the file system”, I’ve noticed the following paragraph:
By modeling IO devices with processes, the Erlang VM allows I/O messages to be routed between different nodes running Distributed Erlang or even exchange files to perform read/write operations across nodes. Neat!
I’ve tried opening a file on a remote node using :rpc.call, but the returned pid seems to get closed immediately afterwards:
You cannot make any assumptions about the process that will perform the apply(). It may be the calling process itself, an rpc server, another server, or a freshly spawned process.
io_device is actually the PID of the process which handles the file. This process monitors the process that originally opened the file (the owner process). If the owner process terminates, the file is closed and the process itself terminates too. If any process to which the io_device is linked terminates, the file will be closed and the process itself will be terminated.
These two combined, I think what happened is that your RPC call started a new process to open the file, then the process was finished and terminated, which also closed the file. Now that you are using a GenServer, it stays alive and thus the opened file also stays open.