aiortc: await pc.close() does not complete if its sending tracks were stopped() before
Our Python app (which uses aiortc
) uses the default asyncio loop
:
loop = asyncio.get_event_loop()
I expect this to be the same loop
used by aiortc
code. When we wish to finish our Python program we close all our asyncio tasks and so on, and also close all aiortc
objects:
async def shutdown() -> None:
# close our channel
await channel.close()
# close all aiortc MediaPlayers
for player in players.values():
if player.audio:
player.audio.stop()
if player.video:
player.video.stop()
# close all aiortc PeerConnections
for pc in pcs.values():
await pc.close()
# stop the loop (just in case)
loop.stop()
try:
loop.run_until_complete(
# our stuff here
)
# reached after calling channel closure
except RuntimeError:
pass
finally:
loop.run_until_complete(
shutdown()
)
The thing is, when calling shutdown()
function, sometimes the python process does NOT terminate. By adding some logs we clearly see that, eventually, a call to await pc.close()
never completes, and that’s the problem.
This usually happens when the webcam is active.
However, if we close all the pcs before we close the players
, then everything works fine. So IMHO there is a bug when closing a MediaPlayer
whose tracks are being used by a PeerConnection
.
This is easily reproducible. We can also just close a specific MediaPlayer
and, if its tracks were being sent by a PeerConnection
, then await pc.close()
does NOT complete.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (4 by maintainers)
Commits related to this issue
- worker.py: some changes to accomodate a bit to a bug in aiortc: https://github.com/aiortc/aiortc/issues/283 — committed to versatica/mediasoup-client-aiortc by ibc 4 years ago
- Fixes #283 - RTCRtpSender: Don't close MediaStreamTrack on close() - RTCRtpSender: close() stops RTP and RTCP sending — committed to jmillan/aiortc by jmillan 4 years ago
- Fixes #283 - MediaPlayer: close av container when there are no remaining tracks - RTCRtpSender: don't close MediaStreamTrack on close() - RTCRtpSender: close() stops sending RTP and RTCP — committed to jmillan/aiortc by jmillan 4 years ago
- Fixes #283 - MediaPlayer: close av container when there are no remaining tracks - RTCRtpSender: don't close MediaStreamTrack on stop() - RTCRtpSender: stop() stops sending RTP and RTCP — committed to jmillan/aiortc by jmillan 4 years ago
- [tests] add a test for MediaPlayer used with RTCPeerConnection Let's see if we can trigger the condition described in #283. — committed to jlaine/aiortc by jlaine 4 years ago
- [tests] add a test for MediaPlayer used with RTCPeerConnection Let's see if we can trigger the condition described in #283. — committed to aiortc/aiortc by jlaine 4 years ago
- [rtp sender] ensure _run_rtp exits cleanly with buggy MediaStreamTracks An exception raised by a MediaStreamTrack's `recv` method can result in a deadlock (see #283), because RTCRtpSender._run_rtp wi... — committed to jlaine/aiortc by jlaine 4 years ago
- [rtp sender] ensure _run_rtp exits cleanly with buggy MediaStreamTracks An exception raised by a MediaStreamTrack's `recv` method can result in a deadlock (see #283), because RTCRtpSender._run_rtp wi... — committed to jlaine/aiortc by jlaine 4 years ago
- [media player] ensure self._player is not None before using it self._player may have been cleared by a call to track.stop() which we were waiting for a frame, so check it is not None before using it.... — committed to jlaine/aiortc by jlaine 4 years ago
- [rtp sender] ensure _run_rtp exits cleanly with buggy MediaStreamTracks An exception raised by a MediaStreamTrack's `recv` method can result in a deadlock (see #283), because RTCRtpSender._run_rtp wi... — committed to aiortc/aiortc by jlaine 4 years ago
- [media player] ensure self._player is not None before using it self._player may have been cleared by a call to track.stop() while we were waiting for a frame, so check it is not None before using it.... — committed to jlaine/aiortc by jlaine 4 years ago
- [media player] ensure self._player is not None before using it self._player may have been cleared by a call to track.stop() while we were waiting for a frame, so check it is not None before using it.... — committed to aiortc/aiortc by jlaine 4 years ago
Hi, I created a PR on this regard #292