amazon-kinesis-video-streams-webrtc-sdk-c
amazon-kinesis-video-streams-webrtc-sdk-c copied to clipboard
[QUESTION] When to call `freePeerConnection()`
I noticed that when calling freePeerConnection(), in the callback that was set using peerConnectionOnConnectionStateChange(), after receiving a RTC_PEER_CONNECTION_STATE_CLOSED that the call to freePeerConnection() would hang for a while. I would see the message "Connection listener handler thread shutdown timed out", from this line. Then my app would segfault in onInboundPacket() from PeerConnection.c. The reason is most likely that there was still some data on the socket that could be read and the ConnectionListener.c would try to read and call the data handler callback (which I free'd).
The RTC_PEER_CONNECTION_STATE_CLOSED is triggered via PeerConnection::onDtlsStateChange() and the socket that was closed is still in the poll descriptor list in ConnectionListener.c. I would say that a less error-prone solution would be to actually change the state to ..._CLOSED when the socket is also removed from the poll read list maybe? I might be wrong here as I'm still learning how this all implemented.
Though, the possible improvements aside, the reason why it's working in the examples is because a peer state flag is changed when a RTC_PEER_CONNECTION_CLOSED event is received and the peer is only later removed through the call to sessionCleanupWait() from Common.c.
This #1142 issue might be relevant, could have been the same issue.
I hope my above rambling makes some sens. I'm curious what would be a correct time to call freePeerConnection()?
It looks like this issue has not been active for a long time. If the issue is not resolved, please add an update to the ticket, else it will be automatically resolved in a few days.
@disa6302 is there anything I can help with to provide more info?
Apologies. Completely missed this issue. For the part where it hangs in onInbound packet, can you attach a stack trace for the team to look at?
This is a very old issue. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to open a new one.