[Rd] Segfault on read.socket with long message

Russell Almond ru@@e|| @end|ng |rom r@|mond@net
Mon May 11 21:40:34 CEST 2020

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

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:

listenerloop <- function (port) {
   flog.trace("Opening Socket on port %d",port)
   sock <- make.socket("localhost",port,server=TRUE)
     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))

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

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

  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
almond using acm.org

More information about the R-devel mailing list