Re: [Rd] Segfault on read.socket with long message
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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Segfault on read.socket with long message
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
Re: [Rd] Segfault on read.socket with long message
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 > alm...@acm.org [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] S3 method dispatch for methods in local environments
Dear All, In R 3.6.3 (and earlier), method dispatch used to work for methods stored in local environments that are attached to the search path. For example: myfun <- function(y) { out <- list(y=y) class(out) <- "myclass" return(out) } print.myclass <- function(x, ...) print(formatC(x$y, format="f", digits=5)) myfun(1:4) # prints: [1] "1.0" "2.0" "3.0" "4.0" rm(print.myclass) myenv <- new.env() myenv$print.myclass <- local(function(x, ...) print(formatC(x$y, format="f", digits=5)), myenv) attach(myenv) myfun(1:4) # still prints: [1] "1.0" "2.0" "3.0" "4.0" But since R 4.0.0, this no longer words and the above prints: $y [1] 1 2 3 4 attr(,"class") [1] "myclass" Is this intended? And is there a way to still make this work? Best, Wolfgang __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S3 method dispatch for methods in local environments
> Viechtbauer, Wolfgang (SP) > on Tue, 12 May 2020 18:05:32 + writes: > Dear All, > In R 3.6.3 (and earlier), method dispatch used to work for methods stored in local environments that are attached to the search path. For example: > myfun <- function(y) { > out <- list(y=y) > class(out) <- "myclass" > return(out) > } > print.myclass <- function(x, ...) print(formatC(x$y, format="f", digits=5)) > myfun(1:4) > # prints: [1] "1.0" "2.0" "3.0" "4.0" > rm(print.myclass) > myenv <- new.env() > myenv$print.myclass <- local(function(x, ...) print(formatC(x$y, format="f", digits=5)), myenv) > attach(myenv) > myfun(1:4) > # still prints: [1] "1.0" "2.0" "3.0" "4.0" > But since R 4.0.0, this no longer words and the above prints: > $y > [1] 1 2 3 4 > attr(,"class") > [1] "myclass" > Is this intended? yes, most probably, unless > And is there a way to still make this work? Using the new .S3method(, , ) had been intended as substitute. Can you try it with your attached-environment (which makes sense!) approach ? Best, Martin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S3 method dispatch for methods in local environments
Indeed, that works: myfun <- function(y) { out <- list(y=y) class(out) <- "myclass" return(out) } myenv <- new.env() myenv$print.myclass <- local(function(x, ...) print(formatC(x$y, format="f", digits=5)), new.env(myenv)) .S3method("print", "myclass", myenv$print.myclass) attach(myenv) myfun(1:4) # [1] "1.0" "2.0" "3.0" "4.0" Thanks for the tip! Best, Wolfgang >-Original Message- >From: Martin Maechler [mailto:maech...@stat.math.ethz.ch] >Sent: Tuesday, 12 May, 2020 21:05 >To: Viechtbauer, Wolfgang (SP) >Cc: r-devel (r-devel@r-project.org) >Subject: Re: [Rd] S3 method dispatch for methods in local environments > >> Viechtbauer, Wolfgang (SP) >> on Tue, 12 May 2020 18:05:32 + writes: > >> Dear All, >> In R 3.6.3 (and earlier), method dispatch used to work for methods >stored in local environments that are attached to the search path. For >example: > >> myfun <- function(y) { >> out <- list(y=y) >> class(out) <- "myclass" >> return(out) >> } > >> print.myclass <- function(x, ...) print(formatC(x$y, format="f", >digits=5)) > >> myfun(1:4) > >> # prints: [1] "1.0" "2.0" "3.0" "4.0" > >> rm(print.myclass) >> myenv <- new.env() >> myenv$print.myclass <- local(function(x, ...) print(formatC(x$y, >format="f", digits=5)), myenv) >> attach(myenv) >> myfun(1:4) > >> # still prints: [1] "1.0" "2.0" "3.0" "4.0" > >> But since R 4.0.0, this no longer words and the above prints: > >> $y >> [1] 1 2 3 4 > >> attr(,"class") >> [1] "myclass" > >> Is this intended? > >yes, most probably, unless > >> And is there a way to still make this work? > >Using the new > > .S3method(, , ) > >had been intended as substitute. Can you try it with your >attached-environment (which makes sense!) approach ? > >Best, >Martin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S3 method dispatch for methods in local environments
Dear Wolfgang, I think this new behaviour is related to the following R 4.0.0 NEWS item: > S3 method lookup now by default skips the elements of the search path between > the global and base environments. Your environment "myenv" is attached at position 2 of the search() path and thus now skipped in S3 method lookup. I have just noticed that attr(methods(class="myclass"), "info") getS3method("print", "myclass") both still find your function in myenv although the generic's UseMethod() won't. I find this a bit confusing. A solution to make R >= 4.0.0 find your method is to register the S3 method using the new function .S3method (intended for R scripts, not packages). After running .S3method("print", "myclass", myenv$print.myclass) your method will be found from the generic. Best regards, Sebastian Am 12.05.20 um 20:05 schrieb Viechtbauer, Wolfgang (SP): > Dear All, > > In R 3.6.3 (and earlier), method dispatch used to work for methods stored in > local environments that are attached to the search path. For example: > > myfun <- function(y) { >out <- list(y=y) >class(out) <- "myclass" >return(out) > } > > print.myclass <- function(x, ...) print(formatC(x$y, format="f", digits=5)) > > myfun(1:4) > > # prints: [1] "1.0" "2.0" "3.0" "4.0" > > rm(print.myclass) > myenv <- new.env() > myenv$print.myclass <- local(function(x, ...) print(formatC(x$y, format="f", > digits=5)), myenv) > attach(myenv) > myfun(1:4) > > # still prints: [1] "1.0" "2.0" "3.0" "4.0" > > But since R 4.0.0, this no longer words and the above prints: > > $y > [1] 1 2 3 4 > > attr(,"class") > [1] "myclass" > > Is this intended? And is there a way to still make this work? > > Best, > Wolfgang > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S3 method dispatch for methods in local environments
Thanks, Sebastian, for the pointer to the NEWS item. After some further search, I also found this in the R Blog: https://developer.r-project.org/Blog/public/2019/08/19/s3-method-lookup/ Best, Wolfgang >-Original Message- >From: R-devel [mailto:r-devel-boun...@r-project.org] On Behalf Of Sebastian >Meyer >Sent: Tuesday, 12 May, 2020 21:17 >To: r-devel@r-project.org >Subject: Re: [Rd] S3 method dispatch for methods in local environments > >Dear Wolfgang, > >I think this new behaviour is related to the following R 4.0.0 NEWS item: > >> S3 method lookup now by default skips the elements of the search path >between the global and base environments. > >Your environment "myenv" is attached at position 2 of the search() path >and thus now skipped in S3 method lookup. > >I have just noticed that > >attr(methods(class="myclass"), "info") >getS3method("print", "myclass") > >both still find your function in myenv although the generic's >UseMethod() won't. I find this a bit confusing. > >A solution to make R >= 4.0.0 find your method is to register the S3 >method using the new function .S3method (intended for R scripts, not >packages). After running > >.S3method("print", "myclass", myenv$print.myclass) > >your method will be found from the generic. > >Best regards, > > Sebastian > > >Am 12.05.20 um 20:05 schrieb Viechtbauer, Wolfgang (SP): >> Dear All, >> >> In R 3.6.3 (and earlier), method dispatch used to work for methods stored >in local environments that are attached to the search path. For example: >> >> myfun <- function(y) { >>out <- list(y=y) >>class(out) <- "myclass" >>return(out) >> } >> >> print.myclass <- function(x, ...) print(formatC(x$y, format="f", >digits=5)) >> >> myfun(1:4) >> >> # prints: [1] "1.0" "2.0" "3.0" "4.0" >> >> rm(print.myclass) >> myenv <- new.env() >> myenv$print.myclass <- local(function(x, ...) print(formatC(x$y, >format="f", digits=5)), myenv) >> attach(myenv) >> myfun(1:4) >> >> # still prints: [1] "1.0" "2.0" "3.0" "4.0" >> >> But since R 4.0.0, this no longer words and the above prints: >> >> $y >> [1] 1 2 3 4 >> >> attr(,"class") >> [1] "myclass" >> >> Is this intended? And is there a way to still make this work? >> >> Best, >> Wolfgang __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] "cd" floating in the air in the man page for paste/paste0
Hi, While reading about the new 'recycle0' argument of paste/paste0, I spotted a mysterious "cd" floating in the air in the man page: recycle0: ‘logical’ indicating if zero-length character arguments (and all zero-length or no arguments when ‘collapse’ is not ‘NULL’) should lead to the zero-length ‘character(0)’. cd ^^ This is in R 4.0.0 Patched and R devel. Cheers, H. -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpa...@fredhutch.org Phone: (206) 667-5791 Fax:(206) 667-1319 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] "cd" floating in the air in the man page for paste/paste0
On 12 May 2020 at 19:59, Hervé Pagès wrote: | While reading about the new 'recycle0' argument of paste/paste0, I | spotted a mysterious "cd" floating in the air in the man page: | |recycle0: ‘logical’ indicating if zero-length character arguments (and | all zero-length or no arguments when ‘collapse’ is not | ‘NULL’) should lead to the zero-length ‘character(0)’. | cd | ^^ | | This is in R 4.0.0 Patched and R devel. Also still in r-devel as of svn r78432: \item{recycle0}{\code{\link{logical}} indicating if zero-length character arguments (and all zero-length or no arguments when \code{collapse} is not \code{NULL}) should lead to the zero-length \code{\link{character}(0)}.}cd ^^ Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R 4.0.1
A quick heads-up: We intend to have a 4.0.1 release some time early June, possibly 6/6. For the R Core Team Peter D. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] "cd" floating in the air in the man page for paste/paste0
Thanks, fixed. Tomas On 5/13/20 5:14 AM, Dirk Eddelbuettel wrote: On 12 May 2020 at 19:59, Hervé Pagès wrote: | While reading about the new 'recycle0' argument of paste/paste0, I | spotted a mysterious "cd" floating in the air in the man page: | |recycle0: ‘logical’ indicating if zero-length character arguments (and | all zero-length or no arguments when ‘collapse’ is not | ‘NULL’) should lead to the zero-length ‘character(0)’. | cd | ^^ | | This is in R 4.0.0 Patched and R devel. Also still in r-devel as of svn r78432: \item{recycle0}{\code{\link{logical}} indicating if zero-length character arguments (and all zero-length or no arguments when \code{collapse} is not \code{NULL}) should lead to the zero-length \code{\link{character}(0)}.}cd ^^ Dirk __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel