diff options
author | scwf <wangfei1@huawei.com> | 2014-10-02 17:47:56 -0700 |
---|---|---|
committer | Andrew Or <andrewor14@gmail.com> | 2014-10-02 17:47:56 -0700 |
commit | 8081ce8bd111923db143abc55bb6ef9793eece35 (patch) | |
tree | 8285642f280a7f07c156e480b4f382d3048bcf0b /core/src/main/scala | |
parent | 127e97bee1e6aae7b70263bc5944b7be6f4e6fea (diff) | |
download | spark-8081ce8bd111923db143abc55bb6ef9793eece35.tar.gz spark-8081ce8bd111923db143abc55bb6ef9793eece35.tar.bz2 spark-8081ce8bd111923db143abc55bb6ef9793eece35.zip |
[SPARK-3755][Core] avoid trying privileged port when request a non-privileged port
pwendell, ```tryPort``` is not compatible with old code in last PR, this is to fix it.
And after discuss with srowen renamed the title to "avoid trying privileged port when request a non-privileged port". Plz refer to the discuss for detail.
Author: scwf <wangfei1@huawei.com>
Closes #2623 from scwf/1-1024 and squashes the following commits:
10a4437 [scwf] add comment
de3fd17 [scwf] do not try privileged port when request a non-privileged port
42cb0fa [scwf] make tryPort compatible with old code
cb8cc76 [scwf] do not use port 1 - 1024
Diffstat (limited to 'core/src/main/scala')
-rw-r--r-- | core/src/main/scala/org/apache/spark/util/Utils.scala | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala index b3025c6ec3..9399ddab76 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -1439,7 +1439,12 @@ private[spark] object Utils extends Logging { val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'" for (offset <- 0 to maxRetries) { // Do not increment port if startPort is 0, which is treated as a special port - val tryPort = if (startPort == 0) startPort else (startPort + offset) % 65536 + val tryPort = if (startPort == 0) { + startPort + } else { + // If the new port wraps around, do not try a privilege port + ((startPort + offset - 1024) % (65536 - 1024)) + 1024 + } try { val (service, port) = startService(tryPort) logInfo(s"Successfully started service$serviceString on port $port.") |