albertosantini / node-rio

Integration with Rserve, a TCP/IP server for R framework
https://github.com/albertosantini/node-conpa
MIT License
176 stars 35 forks source link

SIGPIPE signal on remote Rserve #12

Closed ftrianakast closed 10 years ago

ftrianakast commented 10 years ago

Hi!

I am trying to communicate with a remote Rserve. Locally the nodejs app and Rserve work fine together. However when i use a remote server, Rserve simply says:

 Attaching package: 'rjson'

 The following objects are masked from 'package:RJSONIO':

 fromJSON, toJSON

 The following objects are masked from 'package:jsonlite':

 fromJSON, toJSON

 Loading required package: RCurl
 Loading required package: bitops
 Loading required package: RAmazonS3

 Error in run.Rserve(debug = FALSE, 6311, args = NULL, config.file = "Rserv.conf") : 
 ignoring SIGPIPE signal
 Calls: run.Rserve -> .Call
 Execution halted

I figured that is an error on client because SIGPIPE will be generated when a process writes to a pipe which has been closed by the reader (nodejs app). Probably rio needs to keep alive the connections. When I debug node-rio connect, disconnect and close events are emitted one after another immediately. I think that something is missing in Rio (probably something related with socket management). Correct me otherwise, but i am trying it 2 days ago i can not solve it.

albertosantini commented 10 years ago

Try to enable debug mode and check your Rserve configuration about remote and authentication options.

albertosantini commented 10 years ago

Can you provide any snippet using rio?

ftrianakast commented 10 years ago

Hi Alberto!

I am using a simple call now and fails with SIGPIPE again. My Rserve configuration looks like this:

remote enable
auth disable
fileio enable
maxinbuf 5000000

I am trying from node-rio using this snippet:

Rio.evaluate("pi / 2 * 2", {
    host: 'my_host',
    port: 6311
})

The call arrives to Rserve but SIGPIPE signal is launched.

ftrianakast commented 10 years ago

I also put on DEBUG mode Rserve

albertosantini commented 10 years ago

Enable debug on client side.

rio.enableDebug(true);
rio.evaluate...

Anyway, firstly I would try with RSclient package.

For instance,

library(RSclient)
c <- RSconnect(host = "my_host", port 6311)
RSeval(c, "2+2")
ftrianakast commented 10 years ago

Using RSclient has not problem. The Rserve responds well, without SIGPIPE. Just in case i also use this node_module https://www.npmjs.org/package/rserve-client, and it also works. Setting Rio on debug mode, the console prints this:

 Connected to Rserve 
 Supported capabilities --------------

 Sending command to Rserve
 00000000: 0300 0000 1000 0000 0000 0000 0000 0000  ................
 00000010: 040c 0000 7069 202f 2032 202a 2032 0001  ....pi./.2.*.2..

 Disconnected from Rserve
 Closed from Rserve

I believe that this that i will say is important: I am using a Linux container (LXC) to mount Rserve. For that purpose I am using docker project https://www.docker.io/. The problem is solved if i do not use a LXC. Just is curious for me that Rserve on LXC works with other libraries and not with node-rio. If you want to reproduce the error, just for curiosity, you can use this Dockerfile

https://gist.github.com/ftrianakast/10272777

Run the docker container using this:

docker run -p 6311:6311 --name Rserve image_name

albertosantini commented 10 years ago

Thanks a lot for the details.

I need to investigate further.

albertosantini commented 10 years ago

Due to race conditions (and my poor workflow), maybe the socket is closed too early. https://github.com/albertosantini/node-rio/blob/master/lib/rio.js#L319

Try to comment out that line and repeat the test with LXC, please.

ftrianakast commented 10 years ago

Yes Alberto is that. I comment the line and all work perfectly

Thanks a lot

albertosantini commented 10 years ago

Great. Thanks for the try.

I will fix it in the next hours.

(Te molestare de nuevo cuando he terminado de arregrarlo :)

albertosantini commented 10 years ago

Published release 1.2.1. Thanks for your time.