codeant-ai-for-open-source[bot] commented on code in PR #45729:
URL: https://github.com/apache/superset/pull/45729#discussion_r4374013911
##########
superset/db_engine_specs/mssql.py:
##########
@@ -165,6 +168,31 @@ class MssqlEngineSpec(BaseEngineSpec):
),
}
+ @classmethod
+ def get_cancel_query_id(cls, cursor: Any, query: Query) -> str | None:
+ """Capture the SQL Server session before executing its query."""
+ if not cls.has_query_id_before_execute:
+ return None
+ cursor.execute("SELECT @@SPID")
+ row = cursor.fetchone()
+ return str(row[0]) if row else None
+
+ @classmethod
+ def cancel_query(cls, cursor: Any, query: Query, cancel_query_id: str) ->
bool:
+ """Terminate the captured session using a separate cancellation
connection."""
+ if not cls.has_query_id_before_execute or not
cls.validate_cancel_query_id(
+ cancel_query_id, r"^[0-9]+$"
+ ):
+ return False
+ try:
+ # KILL cannot run inside the fresh cancellation connection's
transaction.
+ cursor.execute("IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION")
+ cursor.execute(f"KILL {cancel_query_id}")
Review Comment:
**Suggestion:** A SPID can be reused after the captured query exits; if
cancellation races with completion, this `KILL` can terminate an unrelated
session that acquired the same ID.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Race condition`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=518d5e2f257c42f38baa9a810283a4f9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=518d5e2f257c42f38baa9a810283a4f9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/mssql.py
**Line:** 190:190
**Comment:**
*Race Condition: A SPID can be reused after the captured query exits;
if cancellation races with completion, this `KILL` can terminate an unrelated
session that acquired the same ID.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45729&comment_hash=6b7670715f58c4c9436b617b6d4da0b9eb9221374179c6ef376f169586efe376&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45729&comment_hash=6b7670715f58c4c9436b617b6d4da0b9eb9221374179c6ef376f169586efe376&reaction=dislike'>๐</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]