meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.22k stars 2.48k forks source link

[1.x] Streaming plugin can leak RTP port #3464

Open woutd opened 3 days ago

woutd commented 3 days ago

What version of Janus is this happening on? 1.2.4

Have you tested a more recent version of Janus too? No

Was this working before? Probably not

Is there a gdb or libasan trace of the issue? No

Additional context When the first media port for a create request is free but the second port is in use Janus returns an error and does not create the streaming mountpoint. But it keeps listening on the first port. It is now unable to free this port.

To reproduce:

Create first mountpoint and listen to 24210 and 24211:

{'janus': 'message', 'body': {'request': 'create', 'type': 'rtp', 'id': '12345', 'is_private': True, 'media': [{'mid': 'video', 'type': 'video', 'iface': '127.0.0.1', 'port': 24210, 'pt': 96, 'codec': 'h264', 'fmtp': 'profile-level-id=42e01f;packetization-mode=1'}, {'mid': 'audio', 'type': 'audio', 'iface': '127.0.0.1', 'port': 24211, 'pt': 111, 'codec': 'opus'}], 'secret': 'XXX', 'pin': 'foobar', 'permanent': True, 'admin_key': 'YYY'}, 'transaction': 'foobar'}

Janus returns:

{'janus': 'success', 'session_id': 8590268524389867, 'transaction': 'foobar', 'sender': 3926924562162867, 'plugindata': {'plugin': 'janus.plugin.streaming', 'data': {'streaming': 'created', 'created': 'mp-12345', 'permanent': True, 'stream': {'id': '12345', 'type': 'live', 'description': 'mp-12345', 'is_private': True, 'host': '127.0.0.1', 'ports': [{'type': 'video', 'mid': 'video', 'port': 24210}, {'type': 'audio', 'mid': 'audio', 'port': 24211}]}}}}

Janus is listening to 24210 and 24211:

udp        0      0 127.0.0.1:24210        0.0.0.0:*                           3541152/janus       
udp        0      0 127.0.0.1:24211        0.0.0.0:*                           3541152/janus 

Try to create second mountpoint to listen on 24212 and 24210:

{'janus': 'message', 'body': {'request': 'create', 'type': 'rtp', 'id': '12346', 'is_private': True, 'media': [{'mid': 'video', 'type': 'video', 'iface': '127.0.0.1', 'port': 24212, 'pt': 96, 'codec': 'h264', 'fmtp': 'profile-level-id=42e01f;packetization-mode=1'}, {'mid': 'audio', 'type': 'audio', 'iface': '127.0.0.1', 'port': 24210, 'pt': 111, 'codec': 'opus'}], 'secret': 'XXX', 'pin': 'foobar', 'permanent': True, 'admin_key': 'YYY'}, 'transaction': 'foobar'}

Janus returns error because 24210 is in use and does not create the mountpoint:

{'janus': 'success', 'session_id': 6373290042750009, 'transaction': 'foobar', 'sender': 7906082748689840, 'plugindata': {'plugin': 'janus.plugin.streaming', 'data': {'streaming': 'event', 'error_code': 456, 'error': "Can't add 'rtp' stream, error creating data source stream"}}}

But is still listening on 24212:

udp        0      0 127.0.0.1:24210        0.0.0.0:*                           3541152/janus       
udp        0      0 127.0.0.1:24211        0.0.0.0:*                           3541152/janus 
udp        0      0 127.0.0.1:24212        0.0.0.0:*                           3541152/janus       

This only happens if the first port is free but the second is not.

atoppi commented 3 days ago

please test #3465

woutd commented 3 days ago

I can confirm #3465 fixes the above issue.

lminiero commented 2 days ago

@woutd thanks for the feedback! We'll add some more cleanup in a few other places where I can see a potential leak happening, and then we'll merge.

woutd commented 2 days ago

Alright, thanks @lminiero and @atoppi!