Skip to content

Fix race condition when deleting labels#4944

Open
philippthun wants to merge 1 commit intocloudfoundry:mainfrom
sap-contributions:fix-labels-delete-race-condition
Open

Fix race condition when deleting labels#4944
philippthun wants to merge 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" = ...))
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.

1 participant