remoter
remoter copied to clipboard
timeout for remoter::batch
Is there a way to specify a timeout for a remoter::batch request, e.g., in case the remote server is non-existent or is not running a remoter server? For example, the following code blocks forever:
remoter::batch(addr = 'non_existent_host', script = 'ls()')
I tried with R.utils::withTimeout
, but is does not work, because I guess that the block happens in C code where user interrupts are not allowed.
Interesting. I'm able to kill it with ctrl-c in a terminal:
> remoter::batch(addr = 'non_existent_host', script = 'ls()')
^CR_zmq_msg_recv errno: 4 strerror: Interrupted system call
Error in unserialize(rmsg) : read error
What OS and R interface are you using?
I can also kill it this way, but I would like to be able to detect if it takes too long. For example, this also blocks, even though I have specified a timeout of 2 seconds:
R.utils::withTimeout({ remoter::batch(addr = 'non_existent_server', script = 'ls()') }, timeout = 2.0, onTimeout = 'silent')
To be more specific, I can kill it if I run it in a cygwin terminal in windows with Rscript:
Rscript -e "remoter::batch(addr = 'non_existent_host', script = 'ls()')"
However, in RStudio, the following blocks and I cannot even kill it with the Stop icon:
remoter::batch(addr = 'non_existent_host', script = 'ls()')
I have investigated a little more and it is not trivial to implement something with a timeout and non-blocking requests. This is due to the ZeroMQ settings used. In fact, with remoter if you make a batch request to a server that is not yet up and start the remoter server later, then the server replies! In practice, I check if port 55555 is open at the server (with a utility like nc) and hope that an actual remoter server is running at this port. We could close the issue if you want.
I add all socket options to pbdZMQ. The CONNECT_TIMEOUT
with SNDTIMEO
and RCVTIMEO
may help on this, but it needs to rewrite a lot of server()
and client()
...