Stan control not work in Mac

Hi, stanimals.

Once again I met some problems when presenting Stan programs. I ran the following code for tutorial on my Mac.

library(rstan)
library(coda)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
rm(list = ls())
set.seed(123)
n <- 300 # sample sie
p <- 3 # dimensions
X <- matrix(rnorm(n*(p-1)), n)
X <- cbind(rep(1, n), X) 

colnames(X) <- c('x1', 'x2', 'x3')

beta0 <- rep(1, p)
PI <- exp(X %*% beta0) / (1 + exp(X %*% beta0)) # sigmoid of linear term
y <- rbinom(n, 1, PI)
df <- data.frame(cbind(y, X))

stan_model <- "
 data {
 int<lower=0> n;
 int<lower=0> p;
 matrix [n, p] X;
 int y[n];
}

 parameters {
 vector[p] beta;
 }

model {

beta ~ normal(0, 100); // prior

 y ~ bernoulli_logit(X * beta); // likelihood

}
 "
data <- list(n=n, p=p, X=X,y=y)
fit_stan <- stan(model_code = stan_model,
                 data = data, chains = 4, iter = 3000, warmup = 1000, control = list(adapt_delta=0.8, max_treedepth=12))
 

But this code cannot work with following error

starting worker pid=32981 on localhost:11387 at 11:27:45.815
starting worker pid=32995 on localhost:11387 at 11:27:45.985
starting worker pid=33009 on localhost:11387 at 11:27:46.153
starting worker pid=33023 on localhost:11387 at 11:27:46.325

SAMPLING FOR MODEL '63e21eb4c35b48d273ba39474c93cf6b' NOW (CHAIN 1).

SAMPLING FOR MODEL '63e21eb4c35b48d273ba39474c93cf6b' NOW (CHAIN 2).

SAMPLING FOR MODEL '63e21eb4c35b48d273ba39474c93cf6b' NOW (CHAIN 3).

SAMPLING FOR MODEL '63e21eb4c35b48d273ba39474c93cf6b' NOW (CHAIN 4).
Error in unserialize(socklist[[n]]) : error reading from connection

If I remove the parameter of “control”, it can work properly.

My R version and computer information are list as follows:

platform       x86_64-apple-darwin17.0     
arch           x86_64                      
os             darwin17.0                  
system         x86_64, darwin17.0          
status                                     
major          4                           
minor          1.0                         
year           2021                        
month          05                          
day            18                          
svn rev        80317                       
language       R                           
version.string R version 4.1.0 (2021-05-18)
nickname       Camp Pontanezen             

And the Stan version is 2.21.0. I have another Mac using M1 processor and I met the same problem. Can anyone tell me how to solve that?

Many thanks! It works now