[Rd] Segfault on read.socket with long message

2020-05-11 Thread Russell Almond



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


Re: [Rd] Segfault on read.socket with long message

2020-05-12 Thread Russell Almond
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).

     --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
alm...@acm.org


[[alternative HTML version deleted]]

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


[Rd] is(x,"ANY") is FALSE

2023-05-02 Thread Russell Almond
I’m somewhat puzzled by the following bit of code on R 4.2.3 (also R 4.2.2)

> df <- data.frame(x=1:3)
> is (df,"ANY")
[1] FALSE

This seem to be false when the first argument is any S3 class, while I would 
think that “ANY” would be true for S3, S4 and reference classes, as well as 
primitive types.

This also seems to be a regression, as code that was previously working no 
longer works.


A little more context on my use.

I’m defining a slot for a reference class using a type union, 
setClass(“MongoDB”,c(“NULL”,”ANY”))

[I should be using setOldClass(“mongo”) here, but I was having trouble 
promoting the S3 “mongo” class I was getting from the library.]

Then when I try to set the corresopnding slot I’m getting an error, because 
“mongo” is not of type MongoDB (even through that is a class union which 
contains “ANY”).  

I can work around the problem by setting the slot to type “ANY”, but then I 
loose the documentation that the intention is that it should a mongo database 
connection.

Did I miss something here?  Or is this an unintended consequence of some other 
change?

Thanks,
  —Russell Almond




[[alternative HTML version deleted]]

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


[Rd] R CMD check --force-biarch

2012-11-28 Thread Russell Almond
I'm having problems getting R CMD check to work correctly on Windows 7 (64
bit) in a package that uses C code.  What I want to do is to be able to pass
the equivalent of the "--force-biarch" option to check, but this is only
supported for INSTALL.

Background:
I'm writing a package (RNetica) which forms a link between R and a
third-party library (Netica.dll).  The vendor supplies this library in both
a 32 bit and a 64 bit version.
Under Linux, I use configure to link against the 32 or 64 bit version of
libnetica.a as appropriate.
Under Windows, I use configure.win to copy the 32 and 64 bit versions to
"$R_PACKAGE_DIR/libs/i386"  and "$R_PACKAGE_DIR/libs/x64" respectively.

Installation:
This mostly works.  If I run R CMD INSTALL RNetica, R detects the
configure.win and only builds the 64 bit version of RNetica.  [I'm not
entirely clear on why R doesn't at least try to build both architectures.
Wouldn't the default assumption be that the author wrote the configure.win
file to handle both cases?]  But if I use R CMD INSTALL RNetica
--force-biarch, it correctly builds and installs both the 32 and 64 bit
versions.  I can verify that I can load my library and call a few functions
that exercise the DLL.

Checking:
 When I run R CMD check RNetica, I get the following problem in my
00install.out log:
> Warning: this package has a non-empty 'configure.win' file,
> so building only the main architecture
It then fails with the message:
> Error:  .onLoad failed in loadNamespace() for 'RNetica', details:
>   Call:  library.dynam("RNetica",pkgname, libname)
>   Error:  DLL 'RNetica' not found:  maybe not installed for this
architecture?
Sure enough, if I check the directory RNetica.Rcheck/RNetica/libs/x64
It has Netica.dll, RNetica.dll, and symbols.rds
If I check the directory RNetica.Rcheck/RNetica/libs/i386
It only has Netica.dll (copied there by the configure.win).

If I run R CMD check RNetica --no-multiarch, this test runs correctly (only
a few warnings about missing Rd files).
If I run R CMD check RNetica --extra-arch, this fails at the same point.

What I think I need to do is somehow pass --force-biarch to the installation
phase of the check script, but --force-biarch is not a legal argument to R
CMD check, and I'm not sure how to quote it.

Thanks in advance for any help.



Russell Almond
ralm...@fsu.edu
alm...@acm.org
http://ralmond.net/

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