From 7517082d0ae5dcd8f3f2d13aee2a13067836a2be Mon Sep 17 00:00:00 2001 From: Marcel Gleeson Date: Tue, 5 Sep 2023 17:14:28 +0200 Subject: [PATCH] fix(@libp2p/webrtc): close data-channel on muxer stream end (#1976) `RTCDataChannel`s are not properly closed after the stream ends. They stay in an open state and eventually the browser will not be able to create more `RTCDataChannel`s with the following error: ``` Uncaught (in promise) DOMException: Failed to execute 'createDataChannel' on 'RTCPeerConnection': RTCDataChannel creation failed ``` Fixes https://github.com/libp2p/js-libp2p/issues/1895 --- packages/transport-webrtc/src/muxer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/transport-webrtc/src/muxer.ts b/packages/transport-webrtc/src/muxer.ts index 7e5b655a3c..991d130230 100644 --- a/packages/transport-webrtc/src/muxer.ts +++ b/packages/transport-webrtc/src/muxer.ts @@ -158,6 +158,7 @@ export class DataChannelMuxer implements StreamMuxer { direction: 'outbound', dataChannelOptions: this.dataChannelOptions, onEnd: () => { + channel.close() // Stream initiator is responsible for closing the channel this.streams = this.streams.filter(s => s.id !== stream.id) this.metrics?.increment({ stream_end: true }) this.init?.onStreamEnd?.(stream)