Skip to content

fix: lock aggregation call to one per user concurrently#784

Open
JoshC8C7 wants to merge 2 commits intomainfrom
fix-transaction-listing-lockup
Open

fix: lock aggregation call to one per user concurrently#784
JoshC8C7 wants to merge 2 commits intomainfrom
fix-transaction-listing-lockup

Conversation

@JoshC8C7
Copy link
Contributor

@JoshC8C7 JoshC8C7 commented Feb 28, 2026

Greptile Summary

Prevented deadlocks during concurrent batch transaction aggregation by using PostgreSQL advisory locks.

  • Used pg_try_advisory_xact_lock with per-user locking to serialize aggregation calls
  • If lock cannot be acquired, aggregation is skipped gracefully since it's a lazy optimization
  • Lock is transaction-scoped and automatically released, preventing resource leaks
  • Read queries remain functional with slightly stale data when aggregation is deferred

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a focused concurrency fix using standard PostgreSQL advisory lock patterns. The implementation correctly uses transaction-level locks, handles lock acquisition failures gracefully, and maintains data correctness even when aggregation is skipped. The lock key is properly scoped per-user with a unique prefix to avoid collisions.
  • No files require special attention

Important Files Changed

Filename Overview
dwctl/src/db/handlers/credits.rs Added per-user advisory lock to prevent concurrent aggregation deadlocks; implementation is clean and handles lock contention gracefully

Last reviewed commit: ee39dd3

@railway-app railway-app bot temporarily deployed to industrious-light / control-layer-pr-784 February 28, 2026 13:39 Destroyed
@railway-app
Copy link

railway-app bot commented Feb 28, 2026

🚅 Deployed to the control-layer-pr-784 environment in industrious-light

Service Status Web Updated (UTC)
control-layer ◻️ Removed (View Logs) Mar 5, 2026 at 8:32 am

@railway-app railway-app bot temporarily deployed to industrious-light / control-layer-pr-784 February 28, 2026 13:43 Destroyed
@JoshC8C7 JoshC8C7 requested a review from fergusfinn March 2, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant