I'm trying to implement a connection between two processes using a simple socket mechanism. The messages are rather long object stored as JSON.

R is crashing with a segmentation fault when I try to read my test message (which is 5305 bytes long). I first send the length in bytes and then I send the actual message.

Here is my R code:

library(jsonlite)
library(futile.logger)
listenerloop <- function (port) {
  flog.trace("Opening Socket on port %d",port)
  sock <- make.socket("localhost",port,server=TRUE)
  on.exit({
    close.socket(sock)
    flog.trace("Closing Socket on port %d",port)
    })
  repeat {
    ## Input a hunk of stuff up to a blank line.
    output <- character()
    repeat {
      inlen <- read.socket(sock,loop=TRUE)
      flog.trace("Got message of length %s",inlen)
      if (inlen=="quit") break
      inmess <- fromJSON(read.socket(sock,as.integer(inlen)),false)
      outmess <- doProcess(inmess)
      output <- toJSON(outmess)
      flog.trace("Sending message of length %s",nchar(output))
      write.socket(sock,paste(nchar(output),"\n"))
      write.socket(sock,output)
    }
  }
}

doProcess() is the payload, but it is not getting that far.  Instead I get:

> listenerloop(12525)
TRACE [2020-05-11 15:21:00] Opening Socket on port 12525
TRACE [2020-05-11 15:21:03] Got message of length 5305
{"StudentRecord":null,"Message":{"_id":624,"app":"ecd://terc.edu/Zoombinis/","uid":2,"context":"PIZZA_PASS1","sender":"DataArcade","mess":"Last Transaction","timestamp":"1570279373.109","processed":false,"data":{"PP29_N_Rejects_Current_Z":0,"PP106_Avg

 *** caught segfault ***
address 0x7ffdf533d0a8, cause 'memory not mapped'

Traceback:
 1: read.socket(sock, as.integer(inlen))
 2: fromJSON(read.socket(sock, as.integer(inlen)), false)
 3: listenerloop(12525)

I have two questions:

1) Can somebody file a bug report on this? I strongly suspect that there is an uncaught error in read.socket(). I'm happy to help, but I don't have access to bugzilla.

2) Anybody know how to read/write long messages to a socket in R?

Thanks in advance.
  --Russell Almond




--
Russell G. Almond
https://ralmond.net
alm...@acm.org

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to