Skip to content

PeerConnection.close() Method is Blocking the Event Loop #326

@mertushka

Description

@mertushka

Describe the Bug

In certain cases, the PeerConnection.close() polyfill seems to block the event loop. Profiling has shown that the PeerConnection.close() method sometimes takes ~1 second to execute instead of the usual few milliseconds.

Additionally, the datachannel.readyState does not always correctly reflect its real state. This inconsistency can lead to issues such as attempting to send messages on a data channel that appears open but is not actually open. Check the additional context for more insight.

To Reproduce

Steps to reproduce the issue:

  1. Open a WebRTC connection.
  2. Trigger a PeerConnection.close() call.
  3. Observe that the event loop may be blocked, even for ~1 second.
  4. Check the datachannel.readyState before and after the .close() call to confirm state inconsistencies.

Expected Behavior

  • The PeerConnection.close() polyfill should clean up the connection asynchronously and avoid blocking the event loop.
  • The datachannel.readyState should accurately reflect the real state of the data channel.

Device Information

  • Node.js Version: 20.x LTS

Additional Context

See: mertushka/haxball.js#44

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions