-
Notifications
You must be signed in to change notification settings - Fork 148
Cursor.close() leaks server-side handle for async commands that were never fetched (#791) #873
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
Open
peco-engineer-bot
wants to merge
2
commits into
main
Choose a base branch
from
ai/issue-791
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,6 +342,62 @@ def test_execute_async__large_result(self, extra_params): | |
|
|
||
| assert len(result) == x_dimension * y_dimension | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "extra_params", | ||
| [ | ||
| {}, | ||
| { | ||
| "use_sea": True, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should never assign use_sea, there are only 2 active modes either default(thrift), or use_kernel which use kernel. |
||
| }, | ||
| ], | ||
| ) | ||
| def test_close_frees_async_handle_without_fetch(self, extra_params): | ||
| """Regression test for #791. | ||
|
|
||
| Cursor.close() must free the server-side statement handle for an | ||
| async-submitted command even when get_async_execution_result() was | ||
| never called. Before the fix, close() only nulled active_command_id | ||
| and (for the never-fetched case) never issued close_command, so the | ||
| handle leaked until the session closed. | ||
| """ | ||
| long_running_query = "SELECT COUNT(*) FROM RANGE(10000 * 16) x JOIN RANGE(10000) y ON FROM_UNIXTIME(x.id * y.id, 'yyyy-MM-dd') LIKE '%not%a%date%'" | ||
| with self.cursor(extra_params) as cursor: | ||
| cursor.execute_async(long_running_query) | ||
|
|
||
| command_id = cursor.active_command_id | ||
| backend = cursor.backend | ||
| assert command_id is not None | ||
|
|
||
| # The handle is live server-side right after async submission. | ||
| state = backend.get_query_state(command_id) | ||
| assert state in ( | ||
| CommandState.PENDING, | ||
| CommandState.RUNNING, | ||
| CommandState.SUCCEEDED, | ||
| ) | ||
|
|
||
| # Close without ever fetching the result. | ||
| cursor.close() | ||
|
|
||
| # The server must no longer report the handle as live. Polling the | ||
| # same command id should either report a terminal CLOSED/CANCELLED | ||
| # state, or raise signalling the command was closed / no longer | ||
| # exists server side (DatabaseError "closed server side" or a | ||
| # RESOURCE_DOES_NOT_EXIST RequestError). Any of these proves the | ||
| # server-side handle was freed by close(). | ||
| try: | ||
| post_close_state = backend.get_query_state(command_id) | ||
| assert post_close_state in ( | ||
| CommandState.CLOSED, | ||
| CommandState.CANCELLED, | ||
| ), f"Handle still live after close(): {post_close_state}" | ||
| except (DatabaseError, RequestError) as e: | ||
| assert ( | ||
| "closed server side" in str(e) | ||
| or "does not exist" in str(e) | ||
| or "RESOURCE_DOES_NOT_EXIST" in str(e) | ||
| ) | ||
|
|
||
|
|
||
| # Exclude Retry tests because they require specific setups, and LargeQueries too slow for core | ||
| # tests | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.