<div dir="ltr">Hi All,<div><br></div><div style>I'm using GStreamer for a AV switch app. Which will recreate the pipelines looks like as following listing repeatedly:</div><div style><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div style>intervideosrc name=source_a channel=composite_a</div><div style>intervideosrc name=source_b channel=composite_b</div><div style>videomixer name=compose</div><div style>source_b. ! video/x-raw,width=100,height=56 </div>
<div style> ! queue2 ! compose.sink_1</div><div style>source_a. ! video/x-raw,width=100,height=56 </div><div style> ! queue2 ! compose.sink_0</div><div style>compose. ! video/x-raw,width=100,height=56</div><div style>
! queue2 ! gdppay ! tcpserversink name=out port=3001</div></blockquote><div style> </div><div style>But it turns out there're socket file descriptors leaking until "<font color="#990000"><b>Too many open files</b></font>" issued and be killed the app. The error looks like:</div>
<div style><br></div><div style><div style="font-family:arial,sans-serif;font-size:13px"><div><font color="#666666">(gst-switch-srv:1709): GLib-ERROR **: <b>Creating pipes for GWakeup: Too many open files</b></font></div>
<div><br></div></div></div><div style>And my code used to recreate the pipelines is gst_worker_reset which is at <a href="https://github.com/duzy/gst-switch/blob/master/tools/gstworker.c#L597">https://github.com/duzy/gst-switch/blob/master/tools/gstworker.c#L597</a> as it's looking like:</div>
<div style><div style><br></div><div style><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;color:rgb(51,51,51);line-height:16px">
<div class="" id="LC611" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">pipeline</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px">workerclass</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">create_pipeline</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px">);</span></div>
<div class="" id="LC612" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">!</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">pipeline</span><span class="" style="margin:0px;padding:0px;border:0px">)</span></div>
<div class="" id="LC613" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">goto</span> <span class="" style="margin:0px;padding:0px;border:0px">error_create_pipeline</span><span class="" style="margin:0px;padding:0px;border:0px">;</span></div>
<div class="" id="LC614" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div class="" id="LC615" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">gst_pipeline_set_auto_flush_bus</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">GST_PIPELINE</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">pipeline</span><span class="" style="margin:0px;padding:0px;border:0px">),</span> <span class="" style="margin:0px;padding:0px;border:0px">FALSE</span><span class="" style="margin:0px;padding:0px;border:0px">);</span></div>
<div class="" id="LC616" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div class="" id="LC617" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">bus</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px">gst_pipeline_get_bus</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">GST_PIPELINE</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">pipeline</span><span class="" style="margin:0px;padding:0px;border:0px">));</span></div>
<div class="" id="LC618" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">!</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">bus</span><span class="" style="margin:0px;padding:0px;border:0px">)</span></div>
<div class="" id="LC619" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">goto</span> <span class="" style="margin:0px;padding:0px;border:0px">error_get_bus</span><span class="" style="margin:0px;padding:0px;border:0px">;</span></div>
<div class="" id="LC620" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div class="" id="LC621" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">watch</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px">gst_bus_add_watch</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">bus</span><span class="" style="margin:0px;padding:0px;border:0px">,</span></div>
<div class="" id="LC622" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">GstBusFunc</span><span class="" style="margin:0px;padding:0px;border:0px">)</span> <span class="" style="margin:0px;padding:0px;border:0px">gst_worker_message</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px">);</span></div>
<div class="" id="LC623" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">!</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">watch</span><span class="" style="margin:0px;padding:0px;border:0px">)</span></div>
<div class="" id="LC624" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">goto</span> <span class="" style="margin:0px;padding:0px;border:0px">error_add_watch</span><span class="" style="margin:0px;padding:0px;border:0px">;</span></div>
<div class="" id="LC625" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div class="" id="LC626" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">workerclass</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">prepare</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">&&</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">!</span><span class="" style="margin:0px;padding:0px;border:0px">workerclass</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span><span class="" style="margin:0px;padding:0px;border:0px">prepare</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker</span><span class="" style="margin:0px;padding:0px;border:0px">))</span></div>
<div class="" id="LC627" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">goto</span> <span class="" style="margin:0px;padding:0px;border:0px">error_prepare</span><span class="" style="margin:0px;padding:0px;border:0px">;</span><div>
<br></div></div></pre></div><div style><br></div><div style>By hacking into <b>tcpserversink</b>, I found that the <b>tcpserversink</b> will emit a <b>client-socket-removed</b> signal and requiring it's client code to manually close the socket, and I've already done it by</div>
<div style><br></div><div style><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;color:rgb(51,51,51);line-height:16px"><div class="" id="LC444" style="margin:0px;padding:0px 0px 0px 10px;border:0px">
<span class="" style="margin:0px;padding:0px;border:0px">g_signal_connect</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">sink</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(221,17,68)">"client-socket-removed"</span><span class="" style="margin:0px;padding:0px;border:0px">,</span></div>
<div class="" id="LC445" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">G_CALLBACK</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">output_client_socket_removed</span><span class="" style="margin:0px;padding:0px;border:0px">),</span> <span class="" style="margin:0px;padding:0px;border:0px">w</span><span class="" style="margin:0px;padding:0px;border:0px">);</span><div>
<br></div></div></pre></div><div style>And:</div><div style><br></div><div style><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;color:rgb(51,51,51);line-height:16px">
<div class="" id="LC418" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">static</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(68,85,136);font-weight:bold">void</span></div>
<div class="" id="LC419" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">output_client_socket_removed</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">GstElement</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">*</span><span class="" style="margin:0px;padding:0px;border:0px">element</span><span class="" style="margin:0px;padding:0px;border:0px">,</span></div>
<div class="" id="LC420" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">GSocket</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">*</span><span class="" style="margin:0px;padding:0px;border:0px">socket</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px">GstComposite</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">*</span><span class="" style="margin:0px;padding:0px;border:0px">composite</span><span class="" style="margin:0px;padding:0px;border:0px">)</span></div>
<div class="" id="LC421" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="" style="margin:0px;padding:0px;border:0px">{</span></div><div class="" id="LC422" style="margin:0px;padding:0px 0px 0px 10px;border:0px">
<span class="" style="margin:0px;padding:0px;border:0px">g_return_if_fail</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">G_IS_SOCKET</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">socket</span><span class="" style="margin:0px;padding:0px;border:0px">));</span></div>
<div class="" id="LC426" style="margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="" style="margin:0px;padding:0px;border:0px">g_socket_close</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">socket</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,134,179)">NULL</span><span class="" style="margin:0px;padding:0px;border:0px">);</span></div>
<div class="" id="LC427" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="" style="margin:0px;padding:0px;border:0px">}</span></div></pre></div><div style><br></div><div style>But it don't solve the socket file descriptor leaks problem. While doing track-fds using <b>valgrind</b>, I got these:</div>
<div><br></div><div><div>==5605== FILE DESCRIPTORS: 822 open at exit.</div><div>......</div><div>==5605== <br></div><div>==5605== Open AF_UNIX socket 821: <unknown></div><div>==5605== at 0x5D13F8A: socketpair (syscall-template.S:82)</div>
<div>==5605== by 0x4EA2227: gst_poll_new (gstpoll.c:569)</div><div>==5605== by 0x4EA22FD: gst_poll_new_timer (gstpoll.c:630)</div><div>==5605== by 0x4E6AA84: gst_bus_constructed (gstbus.c:152)</div><div>==5605== by 0x54A1122: g_object_newv (gobject.c:1747)</div>
<div>==5605== by 0x4E6B105: <b>gst_bus_new</b> (gstbus.c:286)</div><div>==5605== by 0x4E9B6A5: gst_pipeline_init (gstpipeline.c:210)</div><div>==5605== by 0x54BBDDE: g_type_create_instance (gtype.c:1912)</div><div>
==5605== by 0x549F6B7: g_object_constructor (gobject.c:1855)</div><div>==5605== by 0x54A0CB0: g_object_newv (gobject.c:1719)</div><div>==5605== by 0x4E7D44D: gst_element_factory_create (gstelementfactory.c:377)</div>
<div>==5605== by 0x4E7D60E: gst_element_factory_make (gstelementfactory.c:446)</div><div>==5605== by 0x4EDF184: priv_gst_parse_launch (grammar.y:965)</div><div>==5605== by 0x4ED639C: gst_parse_launch_full (gstparse.c:324)</div>
<div>==5605== by 0x405714: gst_worker_create_pipeline (gstworker.c:181)</div><div>==5605== by 0x4052B4: gst_worker_prepare_unsafe (gstworker.c:611)</div><div>==5605== by 0x40560F: <b>gst_worker_reset</b> (gstworker.c:708)</div>
<div>==5605== by 0x40C91D: gst_composite_apply_parameters (gstcomposite.c:332)</div><div>==5605== by 0x40CD17: gst_composite_null (gstcomposite.c:540)</div><div>==5605== by 0x4063D8: gst_worker_message (gstworker.c:438)</div>
<div>......</div></div><div style><br></div><div style><br></div><div style>Do you guys have any suggestion on this? Please help. Is it a <b>bug</b>?</div><div style><br></div><div style>Best Regards Sincerely</div><div style>
Duzy Chan</div><div style><br></div></div></div>