Description
Media stream (particularly audio, but can happen for video as well) stops flowing in one or both directions after exactly 5mn. The issue only occurs when ICE selects the relay candidate (TURN). IPv6 is not impacted, because there are no relay candidates for IPv6 addresses.
The issue is related to the permission that a client using the relay must require from the TURN server in order to allow the peer to send packet the client through the TURN server. Without those permissions, the server would reject the peer's packets. All TURN permissions have a expire time of 5mn as per RFC-5766 section 2.3. The client must send permission's refresh periodically to keep the permission alive.
When ICE starts a new session, it will request an allocation for each local relay candidate, and request permissions for each remote candidates. This is needed in order to perform the connectivity checks for candidate pairs formed by the local relay candidate and the remote candidates. Without those permissions, the connectivity checks would fail. The permission are requested/refreshed either by an explicit STUN request or when TURN binds a data channel (see RFC-5766 for more details).
If the remote candidates are reachable (most likely for reflexive and relay remote candidates), receiving packets from those candidates will be possible even if ICE nominated another pair, because the permission would last for 5mn. After that, the packets would not be relayed by TURN if the permissions are not refreshed as explained earlier.
The root cause was the address used in pj_ice_strans_sendto2. As per pjnath documentation, pj_ice_strans_sendto2() should take the default remote address of the peer (the one present in the c= line of the SDP offer/answer). Even if the default address is typically not reachable, pjnat use this address to map to the appropriate remote address (depending on the current status of ICE connections).