-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Describe the bug
When a Room object is destroyed, the FFI event listener registered during Connect() is not removed. This causes subsequent callbacks to reference a destroyed object, leading to use-after-free crashes.
To Reproduce
- Connect to a room
- Destroy the Room object (or let it go out of scope)
- Reconnect with a new Room
- Crash occurs when FFI dispatches events to the old, destroyed listener
Expected behavior
The FFI listener should be removed in the Room destructor to prevent dangling callbacks.
I tried to fix this by:
- Storing the listener ID during Connect()
- Calling
FfiClient::RemoveListener()in the destructor - Adding a mechanism to wait for in-flight callbacks to complete before destruction
Problem encountered
If a user destroys the Room from within a RoomDelegate callback (e.g., in onDisconnected), the destructor will deadlock because it waits for the callback to finish, but the callback is waiting for the destructor to return.
I'm unsure how to handle this edge case properly.
Metadata
Metadata
Assignees
Labels
No labels