fix(reprocessing): Remove strict equality from check - #123317
Conversation
|
@cursoragent review |
|
Now let me create a comprehensive review of this change. PR Review: Remove strict equality from reprocessing checkSummaryThis PR fixes a race condition in the reprocessing counter logic where concurrent decrements could cause the counter to go negative, preventing The ChangeFile: Changed the completion check from Analysis✅ The Fix is CorrectThe change addresses a real concurrency bug:
🟡 Minor Concerns1. Test Coverage Gap The existing test doesn't cover the negative counter scenario: # tests/sentry/services/eventstore/processing/test_redis_cluster.py
result = store.mark_event_reprocessed(group_id=group_id, num_events=0) # Decrements by 0Recommendation: Add a test case that verifies behavior when @use_redis_cluster()
def test_mark_event_reprocessed_negative_counter() -> None:
"""Test that completion is triggered even when counter goes negative due to concurrent decrements."""
group_id = 5
store = RedisReprocessingStore()
date_created = datetime.now()
# Start with sync_count of 3
store.start_reprocessing(
group_id=group_id, date_created=date_created, sync_count=3, event_count=5
)
# Simulate concurrent decrements that overshoot
result1 = store.mark_event_reprocessed(group_id=group_id, num_events=2) # 3 -> 1
assert result1 is False
result2 = store.mark_event_reprocessed(group_id=group_id, num_events=3) # 1 -> -2
assert result2 is True # Should trigger completion even though negative2. Error Handling in The Optional improvement: def finish_reprocessing(project_id: int, group_id: int) -> None:
from sentry.models.activity import Activity
from sentry.models.group import Group
from sentry.models.groupredirect import GroupRedirect
try:
with transaction.atomic(router.db_for_write(Group)):
group = Group.objects.select_for_update().get(id=group_id)
# ... rest of the logic
except Group.DoesNotExist:
# Already processed by another task, this is expected
logger.info(
"finish_reprocessing called for already-deleted group",
extra={"group_id": group_id, "project_id": project_id}
)
return3. Comment Quality The inline comment is good but could be slightly more specific about the race condition: # Concurrent mark_event_reprocessed calls can cause the counter to overshoot zero
# (e.g., two threads decrementing from 2 -> 0 -> -2). Use `<=` to ensure completion
# is triggered even when the counter goes negative.
return new_decremented_value <= 0Verdict: ✅ APPROVED with minor suggestionsCritical: None - the fix is correct and addresses a real production bug (INC-2491) Nice-to-have:
The core logic is sound and this is a good fix for a concurrency bug. The potential for duplicate |
markstory
left a comment
There was a problem hiding this comment.
Looks like it will be less wrong than before.


ref: INC-2491