Skip to content

Fix RefCell re-entrancy panic during isolate cleanup#572

Open
MarcelKaeding wants to merge 1 commit intomainfrom
fix/refcell-reentrant-borrow-panic
Open

Fix RefCell re-entrancy panic during isolate cleanup#572
MarcelKaeding wants to merge 1 commit intomainfrom
fix/refcell-reentrant-borrow-panic

Conversation

@MarcelKaeding
Copy link

Summary

  • Fixes a Rust panic (RefCell<T> already mutably borrowed) on Android when a Dart isolate exits
  • During on_isolate_destroyed, a mutable RefCell borrow is held while retain() drops removed entries — their DropNotifier destructors attempt to re-borrow the same RefCell, causing a panic
  • drop_manager.rs: Bind the removed value so it outlives the temporary borrow guard, ensuring the RefCell borrow is released before the value's destructors run
  • reader_manager.rs: Collect keys to remove first (immutable borrow), then remove entries one at a time so each mutable borrow is scoped to a single remove() call

Test plan

Fixes #571

🤖 Generated with Claude Code

When a Dart isolate exits, `on_isolate_destroyed` holds a mutable borrow
on a RefCell while removing entries. Dropped entries' DropNotifier
callbacks attempt to re-borrow the same RefCell, causing a panic:
"RefCell<T> already mutably borrowed".

Fix by ensuring RefCell borrows are released before values are dropped:
- drop_manager.rs: bind removed value so it outlives the temporary borrow
- reader_manager.rs: collect keys first, then remove one at a time so
  each borrow is scoped to a single remove() call

Fixes #571

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@knopp
Copy link
Collaborator

knopp commented Feb 19, 2026

I'd need to reproduce this first, but bigger issue here is that super_native_extensions and irondash first need to be migrated to native assets before doing another release.

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.

Rust panic: RefCell already mutably borrowed during isolate cleanup on Android

2 participants