Add concurrent role creation test demonstrating race condition (intentionally fails on main)#327
Closed
pyramation wants to merge 2 commits into
Closed
Add concurrent role creation test demonstrating race condition (intentionally fails on main)#327pyramation wants to merge 2 commits into
pyramation wants to merge 2 commits into
Conversation
This test demonstrates the race condition that occurs when multiple processes attempt to create the same PostgreSQL role simultaneously. On the main branch, this test FAILS with unique_violation error when multiple concurrent CREATE ROLE statements hit the pg_authid_rolname_index. The test includes: - Concurrent role creation test (reproduces the bug) - Performance benchmarks at concurrency levels 2, 4, 8 - Concurrent GRANT operations test - High concurrency stress test with retries This PR intentionally fails on main to demonstrate the problem. Compare against PR #325 (with locks) and PR #326 (no locks) to see fixes. Co-Authored-By: Dan Lynch <pyramation@gmail.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
Related PRsThis PR demonstrates the concurrent role creation race condition that is fixed by:
Note: This test is expected to FAIL on the main branch to demonstrate the bug. It should PASS when applied to either PR #325 or PR #326. Performance ComparisonThe test includes performance benchmarks at concurrency levels 2, 4, and 8 to measure the performance impact of the lock-based vs exceptions-only approaches. Link to Devin run: https://app.devin.ai/sessions/2c33cab4511f4a7897e29001895487df |
This was referenced Nov 18, 2025
- Replace invalid 'CREATE ROLE IF NOT EXISTS' with proper DO block syntax - PostgreSQL doesn't support IF NOT EXISTS for CREATE ROLE - Use IF NOT EXISTS check inside DO block with exception handling - Improve main test to loop 10 times with 6 concurrent attempts - This increases reliability of reproducing the race condition on CI The test intentionally only catches duplicate_object (not unique_violation) in the reproduction test to demonstrate the bug on main branch. Co-Authored-By: Dan Lynch <pyramation@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add concurrent role creation test (reproduces unique_violation bug)
Summary
This PR adds a comprehensive test suite that intentionally demonstrates the race condition in concurrent PostgreSQL role creation on the main branch. The test should FAIL on main and PASS on the fix branches (PR #325 and PR #326).
Key Changes:
packages/pgsql-test/__tests__/postgres-test.concurrent-roles.test.tsThe Bug Being Demonstrated:
When multiple processes attempt to create the same PostgreSQL role simultaneously, the current code only catches
duplicate_objectexceptions. However, under concurrency, the actual error isunique_violation(error code 23505) when both sessions race to insert intopg_authidand hit thepg_authid_rolname_indexunique constraint.Test Cases:
Review & Testing Checklist for Human
CRITICAL - This PR is expected to FAIL on main branch:
should handle concurrent role creation without errors) actually FAILS on main with aunique_violationerrorTest Plan:
Notes
Related PRs:
Why this test is valuable:
Potential Issues:
Session Info: