bluenviron / gortsplib

RTSP 1.0 client and server library for the Go programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

backchannel blocks client in Docker container

cedricve opened this issue · comments

Hey there,

I've been working with the gortsplib during the last weeks, and it all works out very well. Today I tried to compile a new version (including your library), and I found out once package in a docker image, the client is hanging when setting up the backchannel (https://github.com/kerberos-io/agent/blob/port-to-gortsplib/machinery/src/capture/Gortsplib.go#L278).

If I don't request the backchannel and set it up, it does work properly. However if I do run it on my host system (OSX), than I cannot replicate the issue, it looks like something is making it hang in the docker container. As a result all the RTP packet handles are hanging and do not process any data.

Did a bit more research and found it should be something with the Docker networking? or maybe the packet queue, not sure.. Strange thing is that I've implemented backchannel myself in a previous library and that was working in a container. Not sure what is different in your library, it's just using the backchannel connection, and send over the RTP packet on the right channel. https://github.com/bluenviron/gortsplib/blob/main/client.go#L1854C12-L1854C26

Backchannel works on host machine, but stops working when running in a container (if setup into a single client, all other setups will hang). My solution for now is to run Backchannel on a separate client (but disabled it).

kerberos-io/agent@ced9355#diff-94f603be8d4139a09bf19f790a3e4762c351133185f6e127499b0e150376692fR290-R346

I was able to reproduce and created a seperate repo to illustrate the issue. I took the example of the main repo and dockerized it. The RTP packets are received from the udp socket (gstreamer), but nothing is pushed through the backchannel.

See here for source: https://github.com/kerberos-io/backchannel

Digging a bit deeper, it looks like a UDP writer is used to send over the RTP packets to the backchannel, and I believe this is where it fails. I will force the transport to TCP, which might fix the issue, let's see.

Fixed by forcing TCP in the container, without it will try UDP and fail.

transport := gortsplib.TransportTCP
g.Client = gortsplib.Client{
  RequestBackChannels: true,
  Transport:           &transport,
}

@cedricve exactly, when a back channel track is set up, the mechanism that switches protocols automatically gets disabled.
This is because that mechanism works by monitoring incoming packets, and in case of back channels, there are none, so it can't work.
Set the protocol manually. If you're inside a container, use TCP or set network=host.

This issue is being locked automatically because it has been closed for more than 6 months.
Please open a new issue in case you encounter a similar problem.