Repository: spark
Updated Branches:
  refs/heads/branch-1.6 7e17ce5b6 -> 3133d8bd1


[SPARK-11726] Throw exception on timeout when waiting for REST server response

Author: Jacek Lewandowski <lewandowski.ja...@gmail.com>

Closes #9692 from jacek-lewandowski/SPARK-11726.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/3133d8bd
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/3133d8bd
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/3133d8bd

Branch: refs/heads/branch-1.6
Commit: 3133d8bd17c5b467f1fb63716b544b6b15c64fde
Parents: 7e17ce5
Author: Jacek Lewandowski <lewandowski.ja...@gmail.com>
Authored: Tue Nov 17 15:57:43 2015 -0800
Committer: Andrew Or <and...@databricks.com>
Committed: Tue Nov 17 15:57:43 2015 -0800

----------------------------------------------------------------------
 .../spark/deploy/rest/RestSubmissionClient.scala      | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/3133d8bd/core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala
----------------------------------------------------------------------
diff --git 
a/core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala 
b/core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala
index 957a928..f0dd667 100644
--- 
a/core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala
+++ 
b/core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionClient.scala
@@ -19,16 +19,19 @@ package org.apache.spark.deploy.rest
 
 import java.io.{DataOutputStream, FileNotFoundException}
 import java.net.{ConnectException, HttpURLConnection, SocketException, URL}
+import java.util.concurrent.TimeoutException
 import javax.servlet.http.HttpServletResponse
 
 import scala.collection.mutable
+import scala.concurrent.duration._
+import scala.concurrent.{Await, Future}
 import scala.io.Source
 
 import com.fasterxml.jackson.core.JsonProcessingException
 import com.google.common.base.Charsets
 
-import org.apache.spark.{Logging, SparkConf, SPARK_VERSION => sparkVersion}
 import org.apache.spark.util.Utils
+import org.apache.spark.{Logging, SPARK_VERSION => sparkVersion, SparkConf}
 
 /**
  * A client that submits applications to a [[RestSubmissionServer]].
@@ -225,7 +228,8 @@ private[spark] class RestSubmissionClient(master: String) 
extends Logging {
    * Exposed for testing.
    */
   private[rest] def readResponse(connection: HttpURLConnection): 
SubmitRestProtocolResponse = {
-    try {
+    import scala.concurrent.ExecutionContext.Implicits.global
+    val responseFuture = Future {
       val dataStream =
         if (connection.getResponseCode == HttpServletResponse.SC_OK) {
           connection.getInputStream
@@ -251,11 +255,15 @@ private[spark] class RestSubmissionClient(master: String) 
extends Logging {
           throw new SubmitRestProtocolException(
             s"Message received from server was not a 
response:\n${unexpected.toJson}")
       }
-    } catch {
+    }
+
+    try { Await.result(responseFuture, 10.seconds) } catch {
       case unreachable @ (_: FileNotFoundException | _: SocketException) =>
         throw new SubmitRestConnectionException("Unable to connect to server", 
unreachable)
       case malformed @ (_: JsonProcessingException | _: 
SubmitRestProtocolException) =>
         throw new SubmitRestProtocolException("Malformed response received 
from server", malformed)
+      case timeout: TimeoutException =>
+        throw new SubmitRestConnectionException("No response from server", 
timeout)
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to