Skip to content

[SPARK-54434][PYTHON] Use return instead of exit in bin/find-spark-home short-circuit#55817

Open
1fanwang wants to merge 3 commits into
apache:masterfrom
1fanwang:SPARK-54434-find-spark-home-no-exit
Open

[SPARK-54434][PYTHON] Use return instead of exit in bin/find-spark-home short-circuit#55817
1fanwang wants to merge 3 commits into
apache:masterfrom
1fanwang:SPARK-54434-find-spark-home-no-exit

Conversation

@1fanwang
Copy link
Copy Markdown

What changes were proposed in this pull request?

bin/find-spark-home is documented as # Should be included using "source" directive, but its SPARK_HOME-already-set short-circuit calls exit 0. When the script is sourced, that terminates the caller's shell. This PR replaces exit 0 with return 0 2>/dev/null || exit 0 so the script behaves correctly when sourced (the documented path) and still works if executed directly.

A pyspark unit test (test_find_spark_home_script_sourceable) sources the script twice from a subshell and asserts a marker prints after — the test fails on master and passes with this change.

Why are the changes needed?

bin/find-spark-home is sourced by bin/load-spark-env.sh and by user shell setup. As reported on SPARK-54434, if a user accidentally sources bin/find-spark-home twice in the same shell, the second invocation hits the short-circuit and exit 0 closes the interactive shell session.

Reproducer:

export SPARK_HOME=/some/value
source $SPARK_HOME/bin/find-spark-home  # ok
source $SPARK_HOME/bin/find-spark-home  # shell terminates

Does this PR introduce any user-facing change?

No. Users who source bin/find-spark-home no longer lose their shell on the short-circuit path; users who execute it directly see no behavior change.

How was this patch tested?

Added pyspark.tests.test_util.UtilTests.test_find_spark_home_script_sourceable, which sources the script twice from a bash subprocess and asserts a marker prints after the second source. The test fails on master (the marker is never emitted because exit 0 terminates the subshell) and passes with this change.

Was this patch authored or co-authored using generative AI tooling?

No

1fanwang added 3 commits May 12, 2026 00:45
…me short-circuit

bin/find-spark-home is documented to be sourced. When SPARK_HOME is already
set, the short-circuit calls exit 0, which terminates the caller's shell
session if the script is sourced twice (e.g. by accident or by repeated
shell setup). Use return 0 with an exit 0 fallback so the script works
correctly whether sourced (the documented path) or executed.
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant