Skip to content

Commit 2d968f3

Browse files
authored
fix(aci): Don't acquire lock if issue alert dual write is disabled (#92371)
Make the lock acquisition a no-op when dual write is disabled. The locking is there to avoid duplicates being created when trying to get a default error detector; but we only do that for dual write. Being able to avoid the lock is important, as some users are seeing consistent errors from failing to acquire the lock under concurrent load, and we'd like opting out of dual write to mitigate the problem for them while we fix the underlying issue.
1 parent b6a5504 commit 2d968f3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/sentry/projects/project_rules/creator.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import contextlib
12
import logging
2-
from collections.abc import Sequence
3+
from collections.abc import Callable, Sequence
34
from dataclasses import dataclass
4-
from typing import Any
5+
from typing import Any, ContextManager
56

67
from django.db import router, transaction
78
from rest_framework.request import Request
@@ -34,13 +35,21 @@ class ProjectRuleCreator:
3435
request: Request | None = None
3536

3637
def run(self) -> Rule:
37-
try:
38+
# Only acquire a lock if issue alert dual write is enabled.
39+
lock_acquire: Callable[[], ContextManager[None]] = lambda: contextlib.nullcontext()
40+
if features.has(
41+
"organizations:workflow-engine-issue-alert-dual-write",
42+
self.project.organization,
43+
):
3844
lock = locks.get(
3945
f"workflow-engine-project-error-detector:{self.project.id}",
4046
duration=10,
4147
name="workflow_engine_issue_alert",
4248
)
43-
with lock.acquire(), transaction.atomic(router.db_for_write(Rule)):
49+
lock_acquire = lock.acquire
50+
51+
try:
52+
with lock_acquire(), transaction.atomic(router.db_for_write(Rule)):
4453
self.rule = self._create_rule()
4554

4655
if features.has(

0 commit comments

Comments
 (0)