rpc:call/4 documentation states that:
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.
File.open/2 documentation states that:
io_deviceis 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 theio_deviceis 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.






















