codeant-ai-for-open-source[bot] commented on code in PR #43563:
URL: https://github.com/apache/superset/pull/43563#discussion_r3867018786
##########
superset/commands/tasks/submit.py:
##########
@@ -105,67 +131,81 @@ def run_with_info(self) -> tuple["Task", bool]:
user_id=user_id,
)
- # Acquire lock to prevent race conditions during create/join
+ # Acquire the lock around the whole transaction (see docstring): it is
+ # released only after _create_or_join commits.
with task_lock(dedup_key):
- # Check for existing task (safe under lock)
- existing = TaskDAO.find_by_task_key(task_type, task_key, scope,
user_id)
-
- # Get stats logger
- stats_logger: BaseStatsLogger = current_app.config["STATS_LOGGER"]
-
- if existing:
- # Finding an existing task is itself a dedupe (work reused, not
- # re-created), whether the caller becomes a new subscriber or
- # resubmits as an existing one. Count it on the task's
properties.
- existing.update_properties(
- {
- "dedupe_count":
existing.properties_dict.get("dedupe_count", 0)
- + 1
- }
+ return self._create_or_join(task_type, task_key, scope, user_id,
guest_key)
Review Comment:
**Suggestion:** The lock has a fixed 10-second TTL, but this change now
keeps it held through the database commit and dependency resolution. If that
work exceeds the TTL, another submitter can acquire the expired lock before the
first transaction commits, recreate the original deduplication race, and
receive a unique-constraint failure. Extend or renew the lock for the full
transaction, or enforce a critical-section timeout that is safely below the
TTL. [race condition]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Concurrent GTF submissions can still hit duplicate-key failures.
- ⚠️ Async chart-task creation depends on a ten-second lock lifetime.
- ⚠️ Database-backed and Redis-backed locks can expire mid-transaction.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=38ee3e9e2fac4917b910aff7d1c112e9&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=38ee3e9e2fac4917b910aff7d1c112e9&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/commands/tasks/submit.py
**Line:** 136:137
**Comment:**
*Race Condition: The lock has a fixed 10-second TTL, but this change
now keeps it held through the database commit and dependency resolution. If
that work exceeds the TTL, another submitter can acquire the expired lock
before the first transaction commits, recreate the original deduplication race,
and receive a unique-constraint failure. Extend or renew the lock for the full
transaction, or enforce a critical-section timeout that is safely below the TTL.
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%2F43563&comment_hash=82b363741c799b58962caa652f238ed4a5611d046a2bb61e2ca98597afa13530&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43563&comment_hash=82b363741c799b58962caa652f238ed4a5611d046a2bb61e2ca98597afa13530&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]