[Rd] Segfault on read.socket with long message

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Tue May 12 17:41:46 CEST 2020


On 5/12/20 5:25 PM, Russell Almond wrote:
>
> Thanks for the link.  Somehow the information about how to join the 
> bugzilla site was not available at bugzilla and buried in the CRAN web 
> site instructions on reporting bugs (which pointed me at Bugzilla and 
> not the page you showed me).
>
> The example is pretty minimal.  I left the tracing statements 
> (flog.trace()) and the toJSON, fromJSON in as I thought they might 
> provide some context for another method of approaching my problem.
>
> It looks like I'm getting better results using socketConnection() 
> rather than read.socket(), so I'll pursue that solution (but still 
> file a bug report, as it seg faults are never good).
>
Thanks, a report with that example would be useful - if using 
socketConnection() fixes the problem, I guess it makes it more likely 
that the bug is in R, but one never knows before the case is fully analyzed.

Tomas

>     --Russell
>
>
> On 5/12/20 5:30 AM, Tomas Kalibera wrote:
>> 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
>>>
>>>
>>>
>>>
>>
> -- 
> Russell G. Almond
> https://ralmond.net
> almond using acm.org



	[[alternative HTML version deleted]]



More information about the R-devel mailing list