Perf issue 1641 select for update#1990
Merged
crivetimihai merged 34 commits intomainfrom Jan 13, 2026
Merged
Conversation
3932617 to
4006cae
Compare
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Signed-off-by: rakdutta <rakhibiswas@yahoo.com>
Cleanup leftover comments from get_for_update() refactor. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
- Change get_for_update default to skip_locked=False to properly wait for locked rows during conflict checks (prevents race conditions) - Remove FOR UPDATE from get_server (read-only operation) - Remove FOR UPDATE from toggle_gateway_status (holds lock during network I/O which causes timeouts/deadlocks) - Fix unused imports and trailing whitespace in test files - Fix no-op test bodies with proper pytest.skip decorators - Update gateway toggle test to verify regular select is used Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Add is_postgresql() helper that checks both DB env var and DATABASE_URL, so tests run correctly when using either configuration method per PR docs. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
56ddb78 to
dd25b90
Compare
DELETE...RETURNING is not supported on MySQL/MariaDB. Use rowcount check instead which works across all supported databases. Also fixes trailing whitespace in test_tool_service.py and updates test mock to use side_effect for different rowcount values. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Remove unused imports and trailing whitespace from test files modified in this PR. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
crivetimihai
approved these changes
Jan 13, 2026
Member
Code Review Fixes AppliedAfter reviewing this PR, I've applied several fixes to address issues found during review: Critical Fixes
Test Improvements
Commits AddedVerification
Design Note
|
20 tasks
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
* tool,serve Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * resource Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * prompt Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * name conflict Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * conflict Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * gateway Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * a2a Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * tools Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * server Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * text fixed Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * ruff Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test file Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * pylint Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * entity_id fix Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * gateway conflict Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * delete Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test cases fixed Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test fixed Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test cases fixed Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * black Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * server Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * test cases fix Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * flake8 Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * doctest Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * concurrency prompt Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * concurrency Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * ruff Signed-off-by: rakdutta <rakhibiswas@yahoo.com> * chore: Remove commented out db.get() calls Cleanup leftover comments from get_for_update() refactor. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: Address row-level locking issues in PR IBM#1990 - Change get_for_update default to skip_locked=False to properly wait for locked rows during conflict checks (prevents race conditions) - Remove FOR UPDATE from get_server (read-only operation) - Remove FOR UPDATE from toggle_gateway_status (holds lock during network I/O which causes timeouts/deadlocks) - Fix unused imports and trailing whitespace in test files - Fix no-op test bodies with proper pytest.skip decorators - Update gateway toggle test to verify regular select is used Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: Improve PostgreSQL detection in concurrency tests Add is_postgresql() helper that checks both DB env var and DATABASE_URL, so tests run correctly when using either configuration method per PR docs. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: Use rowcount instead of RETURNING for MySQL compatibility DELETE...RETURNING is not supported on MySQL/MariaDB. Use rowcount check instead which works across all supported databases. Also fixes trailing whitespace in test_tool_service.py and updates test mock to use side_effect for different rowcount values. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * chore: Fix lint issues in PR test files Remove unused imports and trailing whitespace from test files modified in this PR. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: rakdutta <rakhibiswas@yahoo.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@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.
closes issue ##1641
This PR addresses performance and data consistency issues under high concurrency by introducing and testing row-level locking using get_for_update across critical service methods. The changes ensure that updates, toggles, and conflict checks on key resources (tools, servers, resources, prompts, gateways, A2A agents) are safe from race conditions, especially when running on PostgreSQL
Key Changes
Implements and tests the use of get_for_update for row-level locking in all major service classes.
Adds a comprehensive new test suite: test_row_level_locking.pyto verify correct locking behavior and prevent race conditions.
Refactors and improves mocking in existing service tests to accurately simulate locking and database behavior.
Updates tool, server, and agent service tests to ensure atomic operations and correct handling of concurrent modifications.
Enhances test coverage for edge cases, including conflict detection and concurrent toggles.
Run the Concurrency Row Locking Integration Test
Option 1: Using Docker (Recommended)
# Start a PostgreSQL container docker run -d \ --name postgres-test \ -e POSTGRES_PASSWORD=test \ -e POSTGRES_DB=test \ -p 5432:5432 \ postgres:15Option 2: Using Local PostgreSQL
Ensure PostgreSQL is running locally, then create a test database and user:
Run the Test