Skip to content

Fix race condition when deleting labels#4944

Merged
philippthun merged 1 commit intocloudfoundry:mainfrom
sap-contributions:fix-labels-delete-race-condition
Mar 24, 2026
Merged

Fix race condition when deleting labels#4944
philippthun merged 1 commit intocloudfoundry:mainfrom
sap-contributions:fix-labels-delete-race-condition

Conversation

@philippthun
Copy link
Member

Concurrent requests updating the same resource's labels could fail with Sequel::NoExistingObject when both try to delete the same label. This occurred because find().destroy loads the model first, then deletes by ID - if another request deletes it in between, the delete affects 0 rows and Sequel raises an error.

Changed to use where().destroy which deletes directly via SQL without loading the model, making it atomic and idempotent.

Also removed unnecessary .try(:destroy) from annotations_update since where() always returns a dataset, never nil.

Observed error:

CF-NoExistingObject: Attempt to delete object did not result in a single row modification (Rows Deleted: 0, SQL: DELETE FROM "service_instance_labels" WHERE ("id" = ...))
  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

Concurrent requests updating the same resource's labels could fail with
Sequel::NoExistingObject when both try to delete the same label. This
occurred because find().destroy loads the model first, then deletes by
ID - if another request deletes it in between, the delete affects 0 rows
and Sequel raises an error.

Changed to use where().destroy which deletes directly via SQL without
loading the model, making it atomic and idempotent.

Also removed unnecessary .try(:destroy) from annotations_update since
where() always returns a dataset, never nil.

Observed error:
CF-NoExistingObject: Attempt to delete object did not result in a single
row modification (Rows Deleted: 0, SQL: DELETE FROM
"service_instance_labels" WHERE ("id" = ...))
@philippthun philippthun merged commit 98eb41d into cloudfoundry:main Mar 24, 2026
16 of 17 checks passed
ari-wg-gitbot added a commit to cloudfoundry/capi-release that referenced this pull request Mar 24, 2026
Changes in cloud_controller_ng:

- Fix race condition when deleting labels
    PR: cloudfoundry/cloud_controller_ng#4944
    Author: Philipp Thun <philipp.thun@sap.com>

- Remove orphaned service_bindings routes
    PR: cloudfoundry/cloud_controller_ng#4948
    Author: Philipp Thun <philipp.thun@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants