Skip to content

Commit a1c6da8

Browse files
authored
webrtc: fix detecting closure of some sessions (#4204) (#4212)
1 parent 5cb5dc4 commit a1c6da8

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

internal/protocols/webrtc/peer_connection.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ func (co *PeerConnection) Start() error {
301301
close(co.failed)
302302

303303
case webrtc.PeerConnectionStateClosed:
304+
// "closed" can arrive before "failed" and without
305+
// the Close() method being called at all.
306+
// It happens when the other peer sends a termination
307+
// message like a DTLS CloseNotify.
308+
select {
309+
case <-co.failed:
310+
default:
311+
close(co.failed)
312+
}
313+
304314
close(co.done)
305315
}
306316
})

internal/servers/webrtc/publisher.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,13 @@
372372
return;
373373
}
374374

375-
if (this.pc.connectionState === 'failed') {
375+
// "closed" can arrive before "failed" and without
376+
// the close() method being called at all.
377+
// It happens when the other peer sends a termination
378+
// message like a DTLS CloseNotify.
379+
if (this.pc.connectionState === 'failed'
380+
|| this.pc.connectionState === 'closed'
381+
) {
376382
this.handleError('peer connection closed');
377383
} else if (this.pc.connectionState === 'connected') {
378384
if (this.conf.onConnected !== undefined) {

internal/servers/webrtc/reader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,13 @@
468468
return;
469469
}
470470

471-
if (this.pc.connectionState === 'failed') {
471+
// "closed" can arrive before "failed" and without
472+
// the close() method being called at all.
473+
// It happens when the other peer sends a termination
474+
// message like a DTLS CloseNotify.
475+
if (this.pc.connectionState === 'failed'
476+
|| this.pc.connectionState === 'closed'
477+
) {
472478
this.handleError('peer connection closed');
473479
}
474480
};

0 commit comments

Comments
 (0)