wso2 / wso2/api-platform

Improve deployment hard limit enforcement to prevent concurrent race conditions

Open
#877 0 comments 0 reactions 1 assignee View on GitHub

@dushaniw is already working on this.

Since Feb 1, 2026.

Dominant language
Go
Stars
71
Forks
111
Avg merge
1d 14h
Merged PRs (30d)
110

Description

Context

This issue tracks an improvement identified during code review of PR #853.

Related PR: https://github.com/wso2/api-platform/pull/853
Related Comment: https://github.com/wso2/api-platform/pull/853#discussion_r2751556691
Requested by: @dushaniw

Problem

In platform-api/src/internal/repository/api.go (CreateDeploymentWithLimitEnforcement method), the current hard limit enforcement can still allow the limit to be exceeded in the following scenarios:

  1. When there are insufficient archived deployments to delete (fewer than needed to make room)
  2. When concurrent inserts occur before the transaction completes

The current logic:

  • Counts total deployments
  • If at/over hard limit, deletes up to 5 oldest archived deployments
  • Inserts the new deployment

This doesn't re-check the count after deletion or prevent concurrent inserts from bypassing the limit.

Suggested Improvement

  1. Acquire a lock for the API+gateway+org combination (e.g., SELECT ... FOR UPDATE or advisory lock)
  2. Calculate exact number of deletions needed: neededDeletes = (count + 1) - hardLimit
  3. Fetch and delete exactly that many archived deployments
  4. Re-check the count after deletion
  5. If there aren't enough archived rows to make room, return a clear limit-reached error instead of proceeding with the insert

Priority

Enhancement - to be addressed in a future PR

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.