Skip to content
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

[4.7.x] Fix race condition causing missing subscription keys by synchronizing key table update. #11312

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 27, 2025

This is an automatic copy of pull request #11302 done by Mergify.


Issue

https://gravitee.atlassian.net/browse/APIM-7382

Description

When multiple subscription calls are made to a shared API key application, all calls seem to succeed, but some subscriptions end up without the API key. This issue affects both v2 and v4 APIs, where simultaneous requests result in a race condition that causes the key binding to fail on certain subscriptions.

Additional context

Reproduction Steps
1. Create an application configured to use a shared API key.
2. Add initial subscriptions to trigger the shared API key setup.
3. Create and publish API key plans for at least three APIs with auto-subscription enabled.
4. Send simultaneous subscription requests.

For sending the subscription requests, you can use the following script. Remember to update the value of applicationId with your own test application, and ensure you have a JSON file named plan_list.json with data in the following format:

[ { "_id": "30f89c18-ac35-4290-b89c-18ac35c2901b" }, { "_id": "d5d02f76-0e94-466e-902f-760e94466ee7" }, { "_id": "337cc9fa-3287-4f6d-bcc9-fa32876f6d6c" } ]

The script is:

run_subscriptions.txt

The Fix
The root cause was a race condition during the API key generation process. The fix involved adding a synchronized block around the critical database update code to ensure that key generation for subscriptions is thread-safe and that all concurrent requests correctly bind the API key.


…izing key table update.

(cherry picked from commit fe45014)
@mergify mergify bot requested a review from a team as a code owner March 27, 2025 12:52
@tjaworski-code tjaworski-code merged commit b00e009 into 4.7.x Mar 27, 2025
13 checks passed
@tjaworski-code tjaworski-code deleted the mergify/bp/4.7.x/pr-11302 branch March 27, 2025 13:22
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