Skip to content

Segfault when closing RTCPeerConnections #35

@dbidwell94

Description

@dbidwell94

Version

Node version: v22.17.1
wrtc version: v0.9.0

Description

I am writing a wrapper around WebRTC to make it more accessible to new programmers. I'm using this library to replace the window.global scoped versions of RTC* classes as global isn't defined in node when testing (this is a browser library).

The test themselves are passing, but when closing connections I see segfaults in the terminal. I thought it was my library, but when I created a basic test just opening an RTCPeerConnection, starting the ice process, and then closing it: it also segfaults.

Reproduction

jest.setup.js

const wrtc = require("@roamhq/wrtc");

global.RTCPeerConnection = wrtc.RTCPeerConnection;
global.RTCSessionDescription = wrtc.RTCSessionDescription;
global.RTCIceCandidate = wrtc.RTCIceCandidate;
global.RTCDataChannel = wrtc.RTCDataChannel;

badtest.test.ts

   it.only("Closes P2P connections correctly", async () => {
    const p2p = new RTCPeerConnection({
      iceServers: [{ urls: ["stun:stun.l.google.com:19302"] }],
    });
    const data = p2p.createDataChannel("testChannel");
    const offer = await p2p.createOffer({ iceRestart: true });
    await p2p.setLocalDescription(offer);

    const dataClosed = new Promise<void>((res) => {
      data.onclose = () => res();
    });

    const peerClosed = new Promise<void>((res) => {
      p2p.onconnectionstatechange = () => {
        if (p2p.connectionState === "closed") res();
      };
    });

    data.close();
    p2p.close();

    await Promise.all([dataClosed, peerClosed]);
  });

Run npx jest (I'm using TypeScript here)

Don't profit :(

Image

External Source

You can clone down and run the tests yourself here. The tests themselves are in src/manager.test.ts

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions