-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1075 End-sync task bug #561
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
Conversation
|
Updates to Preview Branch (eng-1075-end-sync-task-bug) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
…d of an advisory lock.
c375d64 to
1611948
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThe changes modify sync task scheduling across application and database layers. The application adds random jitter (100–199 ms) to rescheduling delays to prevent stampedes. The database introduces a new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant propose_sync_task
participant sync_info
Client->>propose_sync_task: propose_sync_task(target, function, worker, timeout, interval)
Note over propose_sync_task: Validate<br/>timeout >= 1 min<br/>task_interval >= 1 min
alt Validation fails
propose_sync_task-->>Client: NULL
else Validation passes
rect rgb(200, 220, 255)
Note over propose_sync_task, sync_info: Attempt insert or get existing
propose_sync_task->>sync_info: INSERT...ON CONFLICT (sync_target, sync_function)
end
alt Row newly inserted
propose_sync_task->>sync_info: SELECT last_successful_run
propose_sync_task-->>Client: last_successful_run timestamp
else Pre-existing row
rect rgb(255, 220, 200)
Note over propose_sync_task, sync_info: Lock for exclusive access
propose_sync_task->>sync_info: SELECT...FOR UPDATE
end
rect rgb(220, 255, 220)
Note over propose_sync_task: Check timeout & backoff<br/>Apply exponential backoff<br/>to task_interval
end
alt Task timed out or overlapping
propose_sync_task->>sync_info: UPDATE status=timeout<br/>increment failure_count
propose_sync_task-->>Client: next_planned_time
else Task ready to execute
propose_sync_task->>sync_info: UPDATE to active<br/>set worker, timeout, start_time<br/>reset end/start fields
propose_sync_task-->>Client: last_task_end or now()
else Not ready yet
propose_sync_task->>sync_info: UPDATE status/fields as needed
propose_sync_task-->>Client: next_planned_time
end
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs
Pre-merge checks✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧠 Learnings (4)📚 Learning: 2025-06-09T16:57:14.681ZApplied to files:
📚 Learning: 2025-10-18T18:58:16.100ZApplied to files:
📚 Learning: 2025-05-20T03:04:21.602ZApplied to files:
📚 Learning: 2025-05-22T23:50:23.771ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (6)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
sid597
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes what we discovered, LGTM
https://linear.app/discourse-graphs/issue/ENG-1075/end-sync-task-bug
Problem: the pg_advisory lock in propose_sync_task was not the right approach, as the subsequent updates were not visible to other threads when they acquired the lock, and before the release. A more classic 'for update' solves the problem better.
We also noticed a stampede problem in that waiting clients would all start at the same time.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.