Skip to content

[SPARK-51223][CONNECT] Always use an ephemeral port for local connect #49965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pyspark/sql/connect/client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class DefaultChannelBuilder(ChannelBuilder):

@staticmethod
def default_port() -> int:
if "SPARK_TESTING" in os.environ and not is_remote_only():
if "SPARK_LOCAL_REMOTE" in os.environ and not is_remote_only():
from pyspark.sql.session import SparkSession as PySparkSession

# In the case when Spark Connect uses the local mode, it starts the regular Spark
Expand Down
7 changes: 2 additions & 5 deletions python/pyspark/sql/connect/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,8 @@ def _start_connect_server(master: str, opts: Dict[str, Any]) -> None:
overwrite_conf = opts
overwrite_conf["spark.master"] = master
overwrite_conf["spark.local.connect"] = "1"
# Always use an ephemeral port for local connect server
overwrite_conf["spark.connect.grpc.binding.port"] = "0"
os.environ["SPARK_LOCAL_CONNECT"] = "1"

# Configurations to be set if unset.
Expand All @@ -1054,11 +1056,6 @@ def _start_connect_server(master: str, opts: Dict[str, Any]) -> None:
"spark.sql.artifact.isolation.alwaysApplyClassloader": "true",
}

if "SPARK_TESTING" in os.environ:
# For testing, we use 0 to use an ephemeral port to allow parallel testing.
# See also SPARK-42272.
overwrite_conf["spark.connect.grpc.binding.port"] = "0"

origin_remote = os.environ.get("SPARK_REMOTE", None)
try:
if origin_remote is not None:
Expand Down