From tom@@@k@||ber@ @end|ng |rom gm@||@com  Tue May 12 11:30:02 2020
From: tom@@@k@||ber@ @end|ng |rom gm@||@com (Tomas Kalibera)
Date: Tue, 12 May 2020 11:30:02 +0200
Subject: [Rd] Segfault on read.socket with long message
In-Reply-To: <2f337cd2-a94b-e86a-c71d-6d8e4981eceb@ralmond.net>
References: <2f337cd2-a94b-e86a-c71d-6d8e4981eceb@ralmond.net>
Message-ID: <99e31966-a838-3176-36e1-2d7391077017@gmail.com>

Thanks for the report, but it is unlikely anyone would be able to help 
just based on this code fragment. We need a small and minimal but 
complete reproducible example. That example should not use any 
contributed packages (a contributed package may be corrupting memory, 
which may cause R to crash).

It is easy to get a bugzilla account - please see 
https://www.r-project.org/bugs.html for more and for advice on how to 
write bug reports. You could even send the bug report to this list, but 
the key thing is the reproducible example.

Thanks
Tomas

On 5/11/20 9:40 PM, Russell Almond wrote:
>
> 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
>
>
>
>



[Rd] Segfault on read.socket with long message
Tomas Kalibera