Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5722#discussion_r29469152
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1959,30 +1959,41 @@ private[spark] object Utils extends Logging {
        * Attempt to start a service on the given port, or fail after a number 
of attempts.
        * Each subsequent attempt uses 1 + the port used in the previous 
attempt (unless the port is 0).
        *
    -   * @param startPort The initial port to start the service on.
    +   * @param port The minimum and maximum port to start the service on, 
separated by colon.
    +   *             If just set one number, take it as the minimum.
        * @param startService Function to start service on a given port.
        *                     This is expected to throw java.net.BindException 
on port collision.
        * @param conf A SparkConf used to get the maximum number of retries 
when binding to a port.
        * @param serviceName Name of the service.
        */
       def startServiceOnPort[T](
    -      startPort: Int,
    +      port: String,
           startService: Int => (T, Int),
           conf: SparkConf,
           serviceName: String = ""): (T, Int) = {
    -
    -    require(startPort == 0 || (1024 <= startPort && startPort < 65536),
    -      "startPort should be between 1024 and 65535 (inclusive), or 0 for a 
random free port.")
    +    val ports = port.split(":", 2)
    +    val (minPort, maxPort) = if (ports.length == 2) {
    +      (ports(0).toInt, ports(1).toInt)
    +    } else {
    +      (ports(0).toInt, 65535)
    +    }
    +    require(minPort == 0 || (1024 <= minPort && minPort <= 65535),
    +      s"Minimum port ${minPort} should be between 1024 and 65535 
(inclusive)," +
    +        " or 0 for a random free port.")
    +    require(maxPort == 0 || (1024 <= maxPort && maxPort <= 65535),
    +      s"Maximum port ${maxPort} should be between 1024 and 65535 
(inclusive)," +
    +        " or 0 for a random free port.")
    +    require(minPort <= maxPort, s"Minimum ${minPort} port should not be" +
    +      s" less than the maximum ${maxPort}.")
     
         val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'"
         val maxRetries = portMaxRetries(conf)
    --- End diff --
    
    So you can have a case where `maxPort - minPort > maxRetries` and that will 
potentially throw an exception the user doesn't expect, right?
    
    I think the right thing to do here is to set `maxPort` to `minPort + 
maxRetries` if it's not defined. And potentially deprecate 
`spark.port.maxRetries` in the process.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to