How to solve the error with all connections are in use?

3,148 views
Skip to first unread message

Jiaqi Zhang

unread,
Jan 18, 2016, 12:58:12 AM1/18/16
to Stan users mailing list
Hi, All,

I am wondering how can I solve this the error of All connections are in use?

I am running a simulation with Rstan in R, and every time, when I call replicate() function, even for only 100 simulations, there is an error message showing below:

Error in file(file, "r") : all connections are in use
Called from: file(file, "r")
Browse[1]> proc.time() - star
   user  system elapsed 
 247.93    1.23 1416.02 
<simpleError in textConnection("rval", "w", local = TRUE): all connections are in use>
<simpleError in textConnection("rval", "w", local = TRUE): all connections are in use>
<simpleError in textConnection("rval", "w", local = TRUE): all connections are in use>
<simpleError in textConnection("rval", "w", local = TRUE): all connections are in use>
<simpleError in textConnection("rval", "w", local = TRUE): all connections are in use>
<simpleError in textConnection("rval", "w", local = TRUE): all connections are in use>

I googled this error, and used rm(object) and showConnections(all=T), closeAllConnections() in the analysis functions as suggested. But I still encounter this error on Windows OS, the code works quite well on Mac OS. So I am thinking that it is a OS specific issue.

Can anyone help out? 

Sincerely,
Jiaqi
IRT_Analysis.R

Ben Goodrich

unread,
Jan 18, 2016, 1:17:17 AM1/18/16
to Stan users mailing list
On Monday, January 18, 2016 at 12:58:12 AM UTC-5, Jiaqi Zhang wrote:
I am wondering how can I solve this the error of All connections are in use?

In general, this means that you have tried to compile too many Stan programs within an R session. In your case, you should call Stan once outside your Analysis() function that you pass to replicate(). For this purpose, you can call it with

  fit_my_guessing_rasch <- stan(model_code = My_Rasch_guessing, chains = 0)

Then, you could either repeatedly pass that object to the fit argument of stan() or just call your Analysis function as is and I think it would work.

However, it is better to write your Stan program in a text file and follow the suggestions in the startup message when rstan is loaded
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options
(auto_write = TRUE)
options
(mc.cores = parallel::detectCores())

Ben

sepehr akhavan

unread,
Mar 9, 2016, 12:56:08 AM3/9/16
to stan-...@googlegroups.com
Hi Ben,
I have exactly the same issue. I run an stan model over and over (in a loop of size 1000). I only compiled once and every time I fit my stan model, I set the fit argument so that I don't re-compile the code. When I run my code on my own personal computer (Mac) it works, however, when I run it on a unix server, it returns that exact same error: Error in file(file, "r") : all connections are in use. 

Any suggestion? 

Thanks very much,
-Sepehr

Ben Goodrich

unread,
Mar 9, 2016, 1:04:20 AM3/9/16
to Stan users mailing list
On Wednesday, March 9, 2016 at 12:56:08 AM UTC-5, sepehr akhavan wrote:
Any suggestion? 

Hard to say without seeing the code. Are you sure the server is running the same version of R and rstan as on your laptop?

Ben

Sepehr Akhavan

unread,
Mar 9, 2016, 1:48:19 AM3/9/16
to stan-...@googlegroups.com
Ben,
Awesome clue. You solved the issue.
I updated rStan on the server and the issue is gone.

I very much appreciate your help.
Sepehr
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/120yMWXQnfM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages