Error in unserialize(socklist[[n]]) : error reading from connection

I’m using OS X Catalina and Windows 10 in three different computers. Last R version 4.0.2 and last RSTUDIO version 1.3.1073

I install stan following the “https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started” Vignette instructions.

I try to use the “schools.stan” example and I obtain “Error in unserialize(socklist[[n]]) : error reading from connection” in chain 2.

I try this code also:

library(rstan)
library(brms)
SEED <- 1655
set.seed(SEED)
n <- 1e4
x <- rnorm(n)
a <- 2
b <- 3
sigma <- 100
y <- a + bx + sigmarnorm(n)
fake <- data.frame(x, y)
sc<-make_stancode(y ~ x, data=fake)
sd<-make_standata(y ~ x, data=fake)
sm<-stan_model(model_code=sc)
fits<-sampling(sm, data=sd, chain=3)

And I obtain the same error in 3 different computer:2 2 with OS X and 1 with Windows
“Error in unserialize(socklist[[n]]) : error reading from connection” or crash if I change “chain=1” or core=1

Thanks in advanced

I try to use m.cores=1 or chain=1 and I obtain a R crash

Probably I’m doing somnething wrong, but as my first “shoot” I can solve it!!!

Hi Xavier,

I can help troubleshoot your Windows installation, then we can tag someone to help with the Catalina installation.

Can you run the following on your Windows machine and post the output:

Sys.getenv("PATH")
Sys.getenv("BINPREF")
readLines("~/.R/Makevars.win")
readLines("~/.Rprofile")
readLines("~/.Renviron")
devtools::session_info("rstan")

On windows 10 computer:

Sys.getenv(“PATH”)
[1] “C:\estadistica\R\bin\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Acer\abFiles\;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® Management Engine Components\IPT;C:\estadistica\MiKTeX 2.9\miktex\bin\x64\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Skype\Phone\;C:\estadistica\PuTTY\;C:\Program Files (x86)\LyX 2.2\Perl\bin;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\AutoFirma\AutoFirma;C:\Users\Xavier\AppData\Local\Microsoft\WindowsApps;C:\Users\Xavier\AppData\Local\Pandoc\;”

Sys.getenv(“BINPREF”)
[1] “”

readLines("~/.R/Makevars.win")
[1] “”
[2] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”

readLines("~/.Rprofile")
Error in file(con, “r”) : no se puede abrir la conexión
Además: Warning message:
In file(con, “r”) : cannot open the connection
In addition: warning message:
cannot open file ‘C:/Users/Xavier/Documents/.Rprofile’: No such file or directory

readLines("~/.Renviron")
Error in file(con, “r”) : cannot open the connection
In addition: warning message:
cannot open file ‘C:/Users/Xavier/Documents/.Renviron’: No such file or directory

devtools::session_info(“rstan”)

  • Session info ------------------------------------------------------------------------------------
    setting value
    version R version 4.0.2 (2020-06-22)
    os Windows 10 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate Spanish_Spain.1252
    ctype Spanish_Spain.1252
    tz Europe/Paris
    date 2020-09-21

  • Packages ----------------------------------------------------------------------------------------
    ! package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
    backports 1.1.9 2020-08-24 [1] CRAN (R 4.0.2)
    BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.0)
    callr 3.4.4 2020-09-07 [1] CRAN (R 4.0.2)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.2)
    cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.2)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
    curl 4.3 2019-12-02 [1] CRAN (R 4.0.2)
    desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
    digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.2)
    ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
    evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
    fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
    farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.2)
    ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
    glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.2)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.2)
    inline 0.3.16 2020-09-06 [1] CRAN (R 4.0.2)
    isoband 0.2.2 2020-06-20 [1] CRAN (R 4.0.2)
    jsonlite 1.7.1 2020-09-07 [1] CRAN (R 4.0.2)
    labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
    D lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.2)
    lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
    loo 2.3.1 2020-07-14 [1] CRAN (R 4.0.2)
    magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.2)
    MASS 7.3-53 2020-09-09 [1] CRAN (R 4.0.2)
    D Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.2)
    matrixStats 0.56.0 2020-03-13 [1] CRAN (R 4.0.2)
    mgcv 1.8-33 2020-08-27 [1] CRAN (R 4.0.2)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
    nlme 3.1-149 2020-08-23 [1] CRAN (R 4.0.2)
    pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
    pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
    pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
    praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.2)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
    processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2)
    ps 1.3.4 2020-08-11 [1] CRAN (R 4.0.2)
    R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.2)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
    Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
    RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.2)
    D RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.2)
    rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.2)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
    rstan * 2.21.2 2020-07-27 [1] CRAN (R 4.0.2)
    rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.2)
    scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
    StanHeaders * 2.21.0-6 2020-08-16 [1] CRAN (R 4.0.2)
    testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.2)
    tibble 3.0.3 2020-07-10 [1] CRAN (R 4.0.2)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.2)
    V8 3.2.0 2020-06-19 [1] CRAN (R 4.0.2)
    vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.2)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.2)
    withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.2)

[1] C:/estadistica/R/library

D – DLL MD5 mismatch, broken installation.

Thanks! It looks like you missed a step when installing RTools4: https://cran.r-project.org/bin/windows/Rtools/

Can you run:

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

And then restart R/RStudio and try again?

writeLines(‘PATH="{RTOOLS40_HOME}\usr\bin;{PATH}"’, con = “~/.Renviron”)
Error: ‘\u’ used without hex digits in character string starting “'PATH=”${RTOOLS40_HOME}\u"

It looks like it didn’t copy correctly, you need the double backspace before the usr and bin paths (i.e. \\usr\\bin)

1 Like

sm<-stan_model(model_code=sc)
Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/ESTADI~1/rtools40/usr/mingw_/bin/g++’ not found

fits<-sampling(sm, data=sd, chain=3)

WORKS!!!

Thanks

1 Like

Great! That warning is safe to ignore.

Let’s get someone to have a look at your Catalina installation(s) now!

@jonah This user is on Catalina with R 4.0.2 and getting Error in unserialize(socklist[[n]]) : error reading from connection when running a model

1 Like

I’ve only seen rare instances of this on Mac. I think the most recent encounter with this error on Catalina was in the thread Some models run without problems, but more complex give error: Error in unserialize(socklist[[n]]) : error reading/writing from connection. @torkar said that he was able to fix it by removing -march=native from the Makevars file (in this case Makevars and not Makevars.win):

On my Catalina setup I haven’t had problems with this so my Makevars file looks like:

CXX14FLAGS=-O3 -march=native -mtune=native 
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256

but following @torkar’s recommendation you could drop -march=native and try just

CXX14FLAGS=-O3 -mtune=native 
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256

You can open that file for editing using file.edit(file.path(Sys.getenv("HOME"), ".R", "Makevars")).

2 Likes

After some uninstall-install and reboot with yours recomentation WORKS in mac too!!!

THANKS!!

1 Like

Did you remove this?

yes, but then I obtained prep_call_sampler error, after that I Uninstall-install and reboot and then it works.

Thanks

Check Repository for distributing (some) stan-dev R packages | r-packages

and try

install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

I had an old version of rstan (version 2.21.2 from CRAN), and It was showing the error.
A new version, rstan version 2.26.3 (Stan version 2.26.1), doesn’t show the error.

1 Like