# Error in unserialize(socklist\[\[n\]\]), running sampling on rstudio server on AWS

**URL:** <https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208>\
**Category:** RStan\
**Created:** [May 15, 2018, 8:49pm UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208 "2018-05-15T20:49:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shoshievass](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/shoshievass/32/307_2.png) [@shoshievass](https://discourse.mc-stan.org/u/shoshievass)\
**Post date:** [May 15, 2018, 8:49pm UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/1 "2018-05-15T20:49:47Z")

</div>

I’m running rstudioserver using the [AMI: ami-3b0c205e](http://www.louisaslett.com/RStudio_AMI/) on an EC2 AWS instance to run a Stan model that I developed locally on my OSX machine.

Everything seems to work fine and `optimizing` seems to work fine on the model as well. However, when I run my sampling call, I get the error `Error in unserialize(socklist[[n]]) : error reading from connection`. I considered that this might be a memory issue and have tried the xlarge (4 cores, 16gb RAM) and 2xlarge (8 cores, 32gb RAM) instances and got the same error both times. When I run this on my mac, which has 16gb of RAM, sampling is slow but works fine.

The code I’m using to run the model is [here](https://github.com/shoshievass/bridgeConditions/blob/master/runfiles/estimate_decay_msm_april2018.R), though it requires data not on github to run. The model itself is [here](https://github.com/shoshievass/bridgeConditions/blob/master/Models/msm_bridge_decay_v6.stan).

Does anyone know what might be going on?

Below is the session info from the aws rstudioserver session:

> sessionInfo()  
> R version 3.4.2 (2017-09-28)  
> Platform: x86\_64-pc-linux-gnu (64-bit)  
> Running under: Ubuntu 16.04.3 LTS

Matrix products: default  
BLAS: /usr/lib/openblas-base/libblas.so.3  
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:  
[1] LC\_CTYPE=en\_US.UTF-8 LC\_NUMERIC=C LC\_TIME=en\_US.UTF-8 LC\_COLLATE=en\_US.UTF-8  
[5] LC\_MONETARY=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 LC\_PAPER=en\_US.UTF-8 LC\_NAME=C  
[9] LC\_ADDRESS=C LC\_TELEPHONE=C LC\_MEASUREMENT=en\_US.UTF-8 LC\_IDENTIFICATION=C

attached base packages:  
[1] stats graphics grDevices utils datasets methods base

other attached packages:  
[1] rstan\_2.16.2 StanHeaders\_2.16.0-1 bindrcpp\_0.2.2 forcats\_0.3.0 stringr\_1.2.0 dplyr\_0.7.4  
[7] purrr\_0.2.4 readr\_1.1.1 tidyr\_0.8.0 tibble\_1.4.2 ggplot2\_2.2.1 tidyverse\_1.2.1

loaded via a namespace (and not attached):  
[1] Rcpp\_0.12.16 cellranger\_1.1.0 pillar\_1.2.2 compiler\_3.4.2 plyr\_1.8.4 bindr\_0.1.1 tools\_3.4.2  
[8] lubridate\_1.7.4 jsonlite\_1.5 gtable\_0.2.0 nlme\_3.1-131 lattice\_0.20-35 pkgconfig\_2.0.1 rlang\_0.2.0  
[15] psych\_1.8.4 cli\_1.0.0 rstudioapi\_0.7 yaml\_2.1.14 parallel\_3.4.2 haven\_1.1.1 gridExtra\_2.3  
[22] xml2\_1.2.0 httr\_1.3.1 hms\_0.4.2 stats4\_3.4.2 grid\_3.4.2 glue\_1.2.0 inline\_0.3.14  
[29] R6\_2.2.2 readxl\_1.1.0 foreign\_0.8-69 modelr\_0.1.2 reshape2\_1.4.2 magrittr\_1.5 codetools\_0.2-15  
[36] scales\_0.5.0 rvest\_0.3.2 assertthat\_0.2.0 mnormt\_1.5-5 colorspace\_1.3-2 stringi\_1.1.5 lazyeval\_0.2.0  
[43] munsell\_0.4.3 broom\_0.4.4 crayon\_1.3.4 zoo\_1.8-1

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 15, 2018, 10:31pm UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/2 "2018-05-15T22:31:34Z")

</div>

Does it work on AWS with `chains = 1`? You can just do a few iterations to find out.

---

<div class="post-metadata">

**Author:** ![statwonk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/statwonk/32/937_2.png) [@statwonk](https://discourse.mc-stan.org/u/statwonk)\
**Post date:** [May 16, 2018, 12:23am UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/3 "2018-05-16T00:23:44Z")

</div>

I also ran into this error. [In my case](http://discourse.mc-stan.org/t/looking-for-a-stan-program-critique/3865/9?u=statwonk) it was due to running out of memory. I was using the `transformed parameters` block and that really increased memory usage. Bob had suggested doing the transformation in the `model` block and that pratically helped me solve the problem without having to upsize the instance.

---

<div class="post-metadata">

**Author:** ![shoshievass](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/shoshievass/32/307_2.png) [@shoshievass](https://discourse.mc-stan.org/u/shoshievass)\
**Post date:** [May 16, 2018, 11:14am UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/4 "2018-05-16T11:14:03Z")

</div>

Thanks for the replies, guys! I was using the transformed params block excessively too, so following @statwonk’s advice I moved most of the heavy memory stuff out. I then tried out running 20 iterations with `chains = 1` and my rsession failed.

Perhaps there’s a deeper problem with my Stan model?

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 16, 2018, 3:05pm UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/5 "2018-05-16T15:05:20Z")

</div>

Possibly. Are there logs / messages as the R session failed?

---

<div class="post-metadata">

**Author:** ![shoshievass](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/shoshievass/32/307_2.png) [@shoshievass](https://discourse.mc-stan.org/u/shoshievass)\
**Post date:** [May 16, 2018, 3:24pm UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/6 "2018-05-16T15:24:58Z")

</div>

Just this  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/7/73d06f2ed97cf126e0d9f6694778e92abf61f95b.png)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 16, 2018, 4:06pm UTC](https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-running-sampling-on-rstudio-server-on-aws/4208/7 "2018-05-16T16:06:08Z")

</div>

I would try starting an R session and noting what `tempdir()` is. Then, in another shell go to that temporary directory and watch the log file (the one without an extension) until R crashes. My guess is stack overflow.
