-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-48810][CONNECT] Session stop() API should be idempotent and not fail if the session is already closed by the server. #47215
Conversation
try: | ||
PySparkSession._activeSession.stop() | ||
except Exception as e: | ||
warnings.warn( | ||
"session.stop(): Local Spark Connect Server could not be stopped. " | ||
f"Error: ${e}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the underlying Java session.
Unclear. Felt safer such as in the case that the JVM is killed out of band. I don't know all the failure modes in this code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
thanks, merging to master! |
@nija-at please open a 3.5 backport PR if needed, thanks! |
wow @nija-at . please add this to 3.5 as well. |
…t fail if the session is already closed by the server ### What changes were proposed in this pull request? Improve the error handling of the `stop()` API in the `SparkSesion` class to not throw if there is any error related to releasing a session or closing the underlying GRPC channel. Both are best effort. In the case of Pyspark, do not fail if the local Spark Connect service cannot be stopped. ### Why are the changes needed? In some cases, the Spark Connect Service will terminate the session, usually because the underlying cluster or driver has restarted. In the cases, calling stop() throws an error which is unactionable. However, stop() still needs to be called in order to reset the active session. Further, the stop() API should be idempotent. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Attached unit tests. Confirmed that removing the code changes results in the tests failing (as expected). ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#47215 from nija-at/session-stop. Authored-by: Niranjan Jayakar <nija@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
…t fail if the session is already closed by the server ### What changes were proposed in this pull request? Improve the error handling of the `stop()` API in the `SparkSesion` class to not throw if there is any error related to releasing a session or closing the underlying GRPC channel. Both are best effort. In the case of Pyspark, do not fail if the local Spark Connect service cannot be stopped. ### Why are the changes needed? In some cases, the Spark Connect Service will terminate the session, usually because the underlying cluster or driver has restarted. In the cases, calling stop() throws an error which is unactionable. However, stop() still needs to be called in order to reset the active session. Further, the stop() API should be idempotent. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Attached unit tests. Confirmed that removing the code changes results in the tests failing (as expected). ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#47215 from nija-at/session-stop. Authored-by: Niranjan Jayakar <nija@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
…t fail if the session is already closed by the server ### What changes were proposed in this pull request? Improve the error handling of the `stop()` API in the `SparkSesion` class to not throw if there is any error related to releasing a session or closing the underlying GRPC channel. Both are best effort. In the case of Pyspark, do not fail if the local Spark Connect service cannot be stopped. ### Why are the changes needed? In some cases, the Spark Connect Service will terminate the session, usually because the underlying cluster or driver has restarted. In the cases, calling stop() throws an error which is unactionable. However, stop() still needs to be called in order to reset the active session. Further, the stop() API should be idempotent. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Attached unit tests. Confirmed that removing the code changes results in the tests failing (as expected). ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#47215 from nija-at/session-stop. Authored-by: Niranjan Jayakar <nija@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
Improve the error handling of the
stop()
API in theSparkSesion
class to not throw if there is any error related to releasing a session or
closing the underlying GRPC channel. Both are best effort.
In the case of Pyspark, do not fail if the local Spark Connect service
cannot be stopped.
Why are the changes needed?
In some cases, the Spark Connect Service will terminate the session, usually
because the underlying cluster or driver has restarted.
In the cases, calling stop() throws an error which is unactionable. However,
stop() still needs to be called in order to reset the active session.
Further, the stop() API should be idempotent.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Attached unit tests.
Confirmed that removing the code changes results in the
tests failing (as expected).
Was this patch authored or co-authored using generative AI tooling?
No.