simple-peer icon indicating copy to clipboard operation
simple-peer copied to clipboard

RTC peers are not garbage collected in a timely manner on Chromium-based browsers

Open R0quef0rt opened this issue 3 years ago • 2 comments

What version of this package are you using? ^9.9.3

What operating system, Node.js, and npm version? This happens on both Windows 10 and Ubuntu 20.024. It's not an NPM or Node problem.

What happened? This is a known bug in Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=825576

This is currently affecting my ability to use WebTorrent: https://github.com/webtorrent/webtorrent/pull/2017

RTC peers are released too slowly, causing an error that breaks both WebTorrent Desktop and the browser-only version of WebTorrent (while running in Chromium browsers). The following error will be seen in WD's "Developer > Show WebTorrent Process" menu: Failed to construct 'RTCPeerConnection': Cannot create so many PeerConnections

When this occurs, WebTorrent is completely unable to seed data. It is permanently broken until the process has been restarted.

This code can be used to fix the problem:

function forcePeerGC () {
  queueMicrotask(() => {
    let img = document.createElement('img')
    img.src = window.URL.createObjectURL(new Blob([new ArrayBuffer(5e+7)]))
    img.onerror = function () {
      window.URL.revokeObjectURL(this.src)
      img = null
    }
  })
}

setInterval(forcePeerGC, 30000)

What did you expect to happen? Ideally, Chromium would perform proper garbage collection. But since that bug has existed for 3 years, I think it's unlikely to be fixed anytime soon.

Are you willing to submit a pull request to fix this bug? I am willing to do this, though I have tried and I am struggling to figure out how. Tests fail because the "document" object does not exist in Node, and neither does the "new Blob()" function.

R0quef0rt avatar Mar 17 '21 19:03 R0quef0rt