Skip to content

fix: can't stop session issue during creation - #145

Closed
ZhiweiLinnn wants to merge 3 commits into
GoogleCloudDataproc:mainfrom
ZhiweiLinnn:stop-session
Closed

ZhiweiLinnn wants to merge 3 commits into
GoogleCloudDataproc:mainfrom
ZhiweiLinnn:stop-session

Conversation

@ZhiweiLinnn

Copy link
Copy Markdown
Contributor

The spark session creation can't be stopped when users click the execution button. Add except for KeyboardInterrupt to fix.

verified: https://screencast.googleplex.com/cast/NDYyMzU2MDc3MjQxOTU4NHxkYjc1ZWRiMi0yMQ

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ZhiweiLinnn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the user experience by addressing an issue where users could not stop a Spark session creation process. It introduces robust KeyboardInterrupt handling, ensuring that when a user attempts to interrupt a session being created, the session is properly terminated, and associated resources are cleaned up. This prevents orphaned sessions and provides a more responsive and controlled interaction with the session creation workflow.

Highlights

  • KeyboardInterrupt Handling: Implemented KeyboardInterrupt exception handling during Spark session creation, allowing users to gracefully stop the process and terminate the session.
  • Session Termination and Cleanup: Upon KeyboardInterrupt, the system now explicitly terminates the Spark session, stops the progress bar thread, and resets internal active session IDs, ensuring proper resource cleanup.
  • Session Name Format: Updated the format of the session name in _get_exiting_active_session to prepend 'sc://' for consistency.
  • New Test Case: Added a new unit test, test_create_session_keyboard_interrupt, to verify that a KeyboardInterrupt during session creation correctly triggers session termination and cleanup.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly adds handling for KeyboardInterrupt to allow users to stop a Spark session during creation, which is a good improvement. The associated test case is also well-written. However, I've found a critical issue where an incorrect prefix is added to a session name, which will likely break the logic for reusing existing sessions. I've also suggested a medium-severity refactoring to reduce code duplication in the exception handling blocks for better maintainability. Please address the critical issue before merging.

) -> Optional["DataprocSparkSession"]:
s8s_session_id = DataprocSparkSession._active_s8s_session_id
session_name = f"projects/{self._project_id}/locations/{self._region}/sessions/{s8s_session_id}"
session_name = f"sc://projects/{self._project_id}/locations/{self._region}/sessions/{s8s_session_id}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The session_name is being formatted with an sc:// prefix. This prefix is intended for Spark Connect URLs, not for Dataproc API resource names. The session_name variable is passed to get_active_s8s_session_response, which uses it in a GetSessionRequest. The Dataproc API expects a resource name in the format projects/{project}/locations/{region}/sessions/{session_id}. Adding this prefix will cause the API call to fail with an InvalidArgument error. Please remove the sc:// prefix.

Suggested change
session_name = f"sc://projects/{self._project_id}/locations/{self._region}/sessions/{s8s_session_id}"
session_name = f"projects/{self._project_id}/locations/{self._region}/sessions/{s8s_session_id}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a typo?

@medb medb changed the title fix can't stop session issue fix: can't stop session issue during creation Sep 30, 2025
) -> Optional["DataprocSparkSession"]:
s8s_session_id = DataprocSparkSession._active_s8s_session_id
session_name = f"projects/{self._project_id}/locations/{self._region}/sessions/{s8s_session_id}"
session_name = f"sc://projects/{self._project_id}/locations/{self._region}/sessions/{s8s_session_id}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a typo?

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.

3 participants