rtmp2src: handle leak when connection is unsuccessful
We have the live input that is not guaranteed to be always on. So, we create rtmp2src, connect and wait for data. If we get an error we destroy it and retry after a while. This causes program to leak file descriptors, and eventually crash (because linux has file descriptors limit of 1024 per process).
File descriptors belong to RtmpConnection object, which is not always destroyed. I tried to debug but I can't understand the root cause.
To repeat the error: simply point rtmp2src to a valid server with non-existing stream. When you get an error on the bus, destroy the element.
I found at least two scenarios where/how it happens
-
Client connection is successful, we get a connection in client_connect_done, but an error happens after that. For instance, if we get "NetStream.Play.StreamNotFound" error. In connect_task_done we call g_task_propagate_pointer, but it does not return a connection, self->connection is not set and we never call gst_rtmp_connection_close_and_unref. I was able to patch it in my copy (by saving pointer to connection in client_connect_done) but this is an ugly hack.
-
Client connection is unsuccessful, for example we get an error "failed to parse auth rejection" (or, I guess, any other error from send_connect_done). In this case, plugin does not get a reference to connection anywhere and no one else seems to close it.
Either plugin should die cleanly without a leak, or it needs "retry" mode where it retries failed connection.