Skip to content

fix: native observer and object lifecycles around closing a connection - #456

Merged
devopvoid merged 3 commits into
mainfrom
fix/observer-lifecycles
Oct 26, 2026
Merged

devopvoid merged 3 commits into
mainfrom
fix/observer-lifecycles

Conversation

@devopvoid

Copy link
Copy Markdown
Owner
  • RTCPeerConnection.close() called from an observer callback freed the connection while WebRTC was still using it, crashing the VM (e.g. on CONNECTED, or while applying a remote description). Called on the signaling thread, the close now runs once the callback has returned.
  • RTCDtlsTransport held no reference on the native transport, so it pointed to freed memory once the connection had closed and the sender or receiver was gone. It now holds one, released by the new dispose(); getTransport() returns null while there is no transport.
  • A SetSessionDescriptionObserver whose result WebRTC dropped because the connection went away was never called. It now reports INVALID_STATE, as AddIceCandidateObserver already does.

WebRTC posts the result of setting a description and drops it, together
with the observer, when the connection goes away first; the observer was
never called. Like AddIceCandidateObserver, it now reports INVALID_STATE
from its destructor if it has not reported anything yet.
getTransport() handed out a pointer it held no reference on, so once the
connection had closed and the sender or receiver was gone, reading the
transport or unregistering its observer touched freed memory. The Java
object now holds a reference, released by the new dispose(), and
getTransport() returns null while there is no transport.
close() closed and freed the connection right away, while WebRTC goes on
with it after an observer callback returns, e.g. after reporting CONNECTED
or while applying a remote description; the VM crashed. Called on the
factory's signaling thread, close() now posts the close to run once the
callback has returned.
@devopvoid
devopvoid merged commit 73aac5d into main Oct 26, 2026
22 checks passed
@devopvoid
devopvoid deleted the fix/observer-lifecycles branch October 26, 2026 16:37
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.

1 participant