Skip to content

Commit

Permalink
webrtc: fix detecting closure of some sessions (#4204) (#4212)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Feb 1, 2025
1 parent 5cb5dc4 commit a1c6da8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions internal/protocols/webrtc/peer_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ func (co *PeerConnection) Start() error {
close(co.failed)

case webrtc.PeerConnectionStateClosed:
// "closed" can arrive before "failed" and without
// the Close() method being called at all.
// It happens when the other peer sends a termination
// message like a DTLS CloseNotify.
select {
case <-co.failed:
default:
close(co.failed)
}

close(co.done)
}
})
Expand Down
8 changes: 7 additions & 1 deletion internal/servers/webrtc/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@
return;
}

if (this.pc.connectionState === 'failed') {
// "closed" can arrive before "failed" and without
// the close() method being called at all.
// It happens when the other peer sends a termination
// message like a DTLS CloseNotify.
if (this.pc.connectionState === 'failed'
|| this.pc.connectionState === 'closed'
) {
this.handleError('peer connection closed');
} else if (this.pc.connectionState === 'connected') {
if (this.conf.onConnected !== undefined) {
Expand Down
8 changes: 7 additions & 1 deletion internal/servers/webrtc/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,13 @@
return;
}

if (this.pc.connectionState === 'failed') {
// "closed" can arrive before "failed" and without
// the close() method being called at all.
// It happens when the other peer sends a termination
// message like a DTLS CloseNotify.
if (this.pc.connectionState === 'failed'
|| this.pc.connectionState === 'closed'
) {
this.handleError('peer connection closed');
}
};
Expand Down

0 comments on commit a1c6da8

Please sign in to comment.