Skip to content

Commit 4cd7d3f

Browse files
committed
retry backend connection
1 parent 0981dff commit 4cd7d3f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pkg/R/sparkR.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,19 @@ sparkR.init <- function(
110110
mainClass = "edu.berkeley.cs.amplab.sparkr.SparkRBackend",
111111
args = as.character(sparkRBackendPort),
112112
javaOpts = paste("-Xmx", sparkMem, sep = ""))
113-
Sys.sleep(2) # Wait for backend to come up
113+
114+
cat("Waiting JVM bring up ...\n")
115+
while(TRUE) {
116+
if(!connExists(.sparkREnv)) {
117+
Sys.sleep(1)
118+
cat(".")
119+
connectBackend("localhost", sparkRBackendPort) # Connect to it
120+
} else {
121+
cat(" ok.\n")
122+
break
123+
}
124+
}
114125
.sparkREnv$sparkRBackendPort <- sparkRBackendPort
115-
connectBackend("localhost", sparkRBackendPort) # Connect to it
116126

117127
if (nchar(sparkHome) != 0) {
118128
sparkHome <- normalizePath(sparkHome)

0 commit comments

Comments
 (0)