Skip to content

Should garbage collecting RTCDataChannels be observable? #2624

Closed
@jan-ivar

Description

@jan-ivar

A useful feature of data channels is they can detect a remote peer closing. From my stackoverflow answer:

The best way to detect the other peer closing the connection is to always negotiate SCTP data channels with your connection and listen for a data channel's closed event:

This works in all major browsers even when data channels aren't used for anything else, modulo a Firefox GC bug:

pc2.ondatachannel = e => window.keepalive = e.channel; // Firefox GC workaround

Without this workaround or other code actually using the data channel on pc2, Firefox will automatically fire a closed event on pc1 after a few of seconds due to GC/CC. We'd like to fix Firefox, except the spec isn't super clear Firefox is in the wrong.

§ 6.4 Garbage Collection in full:

An RTCDataChannel object MUST not be garbage collected if its

  • [[ReadyState]] slot is "connecting" and at least one event listener is registered for open events, message events, error events, closing events, or close events.
  • [[ReadyState]] slot is "open" and at least one event listener is registered for message events, error events, closing events, or close events.
  • [[ReadyState]] slot is "closing" and at least one event listener is registered for error events, or close events.
  • underlying data transport is established and data is queued to be transmitted.

Interpretation A: It's only talking about the surfaced JS channel object, not its underlying data transport.

The problem with this interpretation is that the spec does not appear to accommodate an underlying data transport outliving its associated JS channel object. Instead it appears to assume the opposite in several places (1, 2, 3).

Interpretation B: It's talking about the surfaced JS channel object and its underlying data transport.

The problem with this interpretation is that it makes garbage collection observable, and would require "fixing" the other browsers to have the same behavior Firefox has (what we called a "bug" above).

Neither of these interpretations seem appealing.

Proposal: Have an RTCPeerConnection hold strong references to all its RTCDataChannels that have not been closed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions