MixinNetwork / kraken

🐙 High performance WebRTC SFU implemented with pure Go.
Apache License 2.0
334 stars 49 forks source link

panic: close of closed channel engine/peer.go:1 77 +0xb1 #34

Closed maggch97 closed 8 months ago

maggch97 commented 8 months ago

My branch is 2 years old and merged fix: https://github.com/MixinNetwork/kraken/pull/33 Not sure if the panic is caused by the fix or if the latest code has fixed this. I will update the info here if I find the root cause.

maggch97 commented 8 months ago

2024/02/25 03:53:56 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnTrack(111, 702176603) 2024/02/25 04:18:03 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnTrack(111, 702176603) end with peer queue closed 2024/02/25 04:18:03 HandlePeer(rid:uid:CLOSED) OnTrack(111, 2389352606) 2024/02/25 04:18:03 HandlePeer(rid:uid:CLOSED) OnTrack(111, 2389352606) end with peer queue closed

maggch97 commented 8 months ago

2024/02/25 03:53:56 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnICEConnectionStateChange(connected) 2024/02/25 03:53:56 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnConnectionStateChange(connected) 2024/02/25 03:53:56 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnTrack(111, 702176603) 2024/02/25 03:54:27 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnSignalingStateChange(have-local-offer) 2024/02/25 03:54:27 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnSignalingStateChange(stable) 2024/02/25 04:14:11 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnSignalingStateChange(have-local-offer) 2024/02/25 04:14:11 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnSignalingStateChange(stable) 2024/02/25 04:18:03 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnSignalingStateChange(have-local-offer) 2024/02/25 04:18:03 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnSignalingStateChange(stable) 2024/02/25 04:18:03 copyTrack(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) EOF 2024/02/25 04:18:03 HandlePeer(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) OnTrack(111, 702176603) end with peer queue closed 2024/02/25 04:18:03 PeerClose(rid:uid:092ae668-493f-4bf7-800a-eca1e365a31f) now 2024/02/25 04:18:03 HandlePeer(rid:uid:CLOSED) OnTrack(111, 2389352606) 2024/02/25 04:18:03 PeerClose(rid:uid:CLOSED) with 2024/02/25 04:18:03 HandlePeer(rid:uid:CLOSED) OnTrack(111, 2389352606) end with peer queue closed 2024/02/25 04:18:03 PeerClose(rid:uid:CLOSED) now 2024/02/25 04:18:03 PeerClose(rid:uid:CLOSED) already

OnTrack is called when Peer is closing

maggch97 commented 8 months ago
    peer.pc.OnTrack(func(rt *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
        if peer.cid == peerTrackClosedId {
            logger.Printf("HandlePeer(%s) OnTrack(%d, %d) closed\n", peer.id(), rt.PayloadType(), rt.SSRC())
            return
        }

an adhoc fix

maggch97 commented 8 months ago

The current design of OnTrack require this function can only be called once

cedricfung commented 8 months ago

Thank you. Can you submit a PR for this fix?

maggch97 commented 8 months ago

Thank you. Can you submit a PR for this fix?

Above adhoc fix is not work, currently I just add a recover in copyTrack. If I found a good solution later, I will creat a PR.

cedricfung commented 8 months ago

Fixed https://github.com/MixinNetwork/kraken/commit/ce7ec29118bcedf988923d3a883300d8ec2fa341