chr15m / bugout

Back end web app services over WebRTC.
https://chr15m.github.io/bugout
MIT License
612 stars 59 forks source link

Bump WebTorrent to latest: Cannot read property 'setRemoteDescription' of undefined #47

Closed draeder closed 3 years ago

draeder commented 3 years ago

Using the browser version of Bugout, I am getting this error Cannot read property 'setRemoteDescription' of undefined after a short period of time. When this happens, peers stop communicating with each other.

Here is the stack trace:

bugout.min.js:11 Uncaught TypeError: Cannot read property 'setRemoteDescription' of undefined
    at Peer.signal (bugout.min.js:11)
    at WebSocketTracker._onAnnounceResponse (bugout.min.js:1)
    at WebSocketTracker._onSocketData (bugout.min.js:1)
    at Socket._onSocketDataBound (bugout.min.js:1)
    at emitOne (bugout.min.js:6)
    at Socket.EventEmitter.emit (bugout.min.js:6)
    at addChunk (bugout.min.js:11)
    at readableAddChunk (bugout.min.js:11)
    at Socket.Readable.push (bugout.min.js:11)
    at Socket._onMessage (bugout.min.js:11)
signal @ bugout.min.js:11
_onAnnounceResponse @ bugout.min.js:1
_onSocketData @ bugout.min.js:1
_onSocketDataBound @ bugout.min.js:1
emitOne @ bugout.min.js:6
EventEmitter.emit @ bugout.min.js:6
addChunk @ bugout.min.js:11
readableAddChunk @ bugout.min.js:11
Readable.push @ bugout.min.js:11
_onMessage @ bugout.min.js:11
Socket._ws.onmessage @ bugout.min.js:11

I traced the issue to WebTorrent; specifically it's use of simple-peer to negotiate the WebRTC connections between the connected browsers.

There have been a lot of updates to WebTorrent recently, so I forked Bugout, bumped the WebTorrent dependency to the latest (^1.0.2), and ran tests. All tests succeeded--although the RPC server response test took much longer after the bump than prior to it.

Since bumping WebTorrent to the latest, the error is no longer happening. I've had 3 peers connected together for a while now without any issues.

Submitting a PR.

draeder commented 3 years ago

By the way, I had 5 bugout peers running for about 4 days straight with the version of bugout using the updated webtorrent dependency without the errors described in this issue. I'm 100% confident this PR will fix.