Skip to content

Commit e0e3c25

Browse files
committed
Wrap try block around getReponseCode; re-enable keep-alive by closing error stream
1 parent 961c284 commit e0e3c25

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

repl/src/main/scala/org/apache/spark/repl/ExecutorClassLoader.scala

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package org.apache.spark.repl
1919

20-
import java.io.{ByteArrayOutputStream, InputStream}
20+
import java.io.{IOException, ByteArrayOutputStream, InputStream}
2121
import java.net.{HttpURLConnection, URI, URL, URLEncoder}
2222

23+
import scala.util.control.NonFatal
24+
2325
import org.apache.hadoop.fs.{FileSystem, Path}
2426

2527
import org.apache.spark.{SparkConf, SparkEnv, Logging}
@@ -89,11 +91,23 @@ class ExecutorClassLoader(conf: SparkConf, classUri: String, parent: ClassLoader
8991
connection.setReadTimeout(httpUrlConnectionTimeoutMillis)
9092
}
9193
connection.connect()
92-
if (connection.getResponseCode != 200) {
93-
connection.disconnect()
94-
throw new ClassNotFoundException(s"Class file not found at URL $url")
95-
} else {
96-
connection.getInputStream
94+
try {
95+
if (connection.getResponseCode != 200) {
96+
// Close the error stream so that the connection is eligible for re-use
97+
try {
98+
connection.getErrorStream.close()
99+
} catch {
100+
case ioe: IOException =>
101+
logError("Exception while closing error stream", ioe)
102+
}
103+
throw new ClassNotFoundException(s"Class file not found at URL $url")
104+
} else {
105+
connection.getInputStream
106+
}
107+
} catch {
108+
case NonFatal(e) if !e.isInstanceOf[ClassNotFoundException] =>
109+
connection.disconnect()
110+
throw e
97111
}
98112
}
99113

0 commit comments

Comments
 (0)