Skip to content

Idempotent queue_free() - #1404

Open
OldDev78 wants to merge 2 commits into
Redot-Engine:masterfrom
OldDev78:idempotent-queue-free
Open

Idempotent queue_free()#1404
OldDev78 wants to merge 2 commits into
Redot-Engine:masterfrom
OldDev78:idempotent-queue-free

Conversation

@OldDev78

@OldDev78 OldDev78 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Makes Object queuing for deletion through queue_free() idempotent.
Currently, an object for can be queued for deletion twice, leaving to the SceneTree to check through the instance ID if the object already was deleted or not just before deleting it. This mechanism is still prone to race conditions, even with the mutex lock.

The _is_queued_for_deletion flag needs to be atomic, so that the flagging is effective on the first call and always verifiable, irrespective of which thread queries this state.
Surprisingly, SceneTree never checked for this flag before pushing the object for deletion. A simple check before pushing the object pointer to the queue makes the request idempotent.

Summary by CodeRabbit

  • Bug Fixes
    • Improved thread safety when tracking objects queued for deletion.
    • Prevented objects from being added to the deletion queue more than once.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: fb4993fa-6747-4297-bbfd-cc534a22cf6f

📥 Commits

Reviewing files that changed from the base of the PR and between a7e798c and ec1c5c0.

📒 Files selected for processing (3)
  • core/object/object.cpp
  • core/object/object.h
  • scene/main/scene_tree.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The deletion flag now uses atomic access. SceneTree::queue_delete checks the flag before adding an object to the deletion queue, preventing duplicate entries.

Changes

Deletion queue handling

Layer / File(s) Summary
Atomic deletion state and queue deduplication
core/object/object.h, core/object/object.cpp, scene/main/scene_tree.cpp
Object stores its deletion flag as std::atomic<bool> and reads it with an atomic load. SceneTree::queue_delete skips objects already queued for deletion.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to ec1c5

Repeated queue_free() requests now enqueue an object only once while preserving thread-safe deletion-state access. No merge-blocking risk remains.

Suggested reviewers: arctis-fireblight, generalprotectionfault

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making queue_free() idempotent by preventing duplicate deletion requests.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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