<div dir="ltr">And things in <b>gst_multi_socket_sink_start_pre</b> are now attracting my attentions, because this is where <b>g_main_context_new</b> was called. And <b>GWakup</b> is like to be used only in <b>GMainContext</b>.<div>

<br></div><div style><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style><div style><font color="#666666">static gboolean<br>gst_multi_socket_sink_start_pre (GstMultiHandleSink * mhsink)<br>{<br>

  GstMultiSocketSink *mssink = GST_MULTI_SOCKET_SINK (mhsink);<br>  GstMultiHandleSinkClass *mhsinkclass =<br>      GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);<br>  GList *clients;<br><br>  GST_INFO_OBJECT (mssink, "starting");<br>

<br>  mssink->main_context = <b>g_main_context_new</b> ();<br><br>  CLIENTS_LOCK (mhsink);<br>  for (clients = mhsink->clients; clients; clients = clients->next) {<br>    GstSocketClient *client = clients->data;<br>

    GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;<br><br>    if (client->source)<br>      continue;<br>    mhsinkclass->hash_adding (mhsink, mhclient);<br>  }<br>  CLIENTS_UNLOCK (mhsink);<br><br>

  return TRUE;<br>}</font><br></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style><div style><br></div></div></blockquote>And here is g_main_context_new looks like:</div>

<div style><br></div><div style><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style><div style><font color="#666666">GMainContext *</font></div><div style><font color="#666666">g_main_context_new (void)</font></div>

<div style><font color="#666666">{</font></div><div style><font color="#666666">  static gsize initialised;</font></div><div style><font color="#666666">  GMainContext *context;</font></div><div style><font color="#666666"><br>

</font></div><div style><font color="#666666">  if (g_once_init_enter (&initialised))</font></div><div style><font color="#666666">    {</font></div><div style><font color="#666666">#ifdef G_MAIN_POLL_DEBUG</font></div>

<div style><font color="#666666">      if (getenv ("G_MAIN_POLL_DEBUG") != NULL)</font></div><div style><font color="#666666">        _g_main_poll_debug = TRUE;</font></div><div style><font color="#666666">#endif</font></div>

<div style><font color="#666666"><br></font></div><div style><font color="#666666">      g_once_init_leave (&initialised, TRUE);</font></div><div style><font color="#666666">    }</font></div><div style><font color="#666666"><br>

</font></div><div style><font color="#666666">  context = g_new0 (GMainContext, 1);</font></div><div style><font color="#666666"><br></font></div><div style><font color="#666666">  g_mutex_init (&context->mutex);</font></div>

<div style><font color="#666666">  g_cond_init (&context->cond);</font></div><div style><font color="#666666"><br></font></div><div style><font color="#666666">  context->owner = NULL;</font></div><div style><font color="#666666">  context->waiters = NULL;</font></div>

<div style><font color="#666666"><br></font></div><div style><font color="#666666">  context->ref_count = 1;</font></div><div style><font color="#666666"><br></font></div><div style><font color="#666666">  context->next_id = 1;</font></div>

<div style><font color="#666666">  </font></div><div style><font color="#666666">  context->source_list = NULL;</font></div><div style><font color="#666666">  </font></div><div style><font color="#666666">  context->poll_func = g_poll;</font></div>

<div style><font color="#666666">  </font></div><div style><font color="#666666">  context->cached_poll_array = NULL;</font></div><div style><font color="#666666">  context->cached_poll_array_size = 0;</font></div>
<div style>
<font color="#666666">  </font></div><div style><font color="#666666">  context->pending_dispatches = g_ptr_array_new ();</font></div><div style><font color="#666666">  </font></div><div style><font color="#666666">  context->time_is_fresh = FALSE;</font></div>

<div style><font color="#666666">  </font></div><div style><font color="#666666">  context->wakeup = <b>g_wakeup_new</b> ();</font></div><div style><font color="#666666">  g_wakeup_get_pollfd (context->wakeup, &context->wake_up_rec);</font></div>

<div style><font color="#666666">  g_main_context_add_poll_unlocked (context, 0, &context->wake_up_rec);</font></div><div style><font color="#666666"><br></font></div><div style><font color="#666666">  G_LOCK (main_context_list);</font></div>

<div style><font color="#666666">  main_context_list = g_slist_append (main_context_list, context);</font></div><div style><font color="#666666"><br></font></div><div style><font color="#666666">#ifdef G_MAIN_POLL_DEBUG</font></div>

<div style><font color="#666666">  if (_g_main_poll_debug)</font></div><div style><font color="#666666">    g_print ("created context=%p\n", context);</font></div><div style><font color="#666666">#endif</font></div>

<div style><font color="#666666"><br></font></div><div style><font color="#666666">  G_UNLOCK (main_context_list);</font></div><div style><font color="#666666"><br></font></div><div style><font color="#666666">  return context;</font></div>

<div style><font color="#666666">}</font></div><div style><br></div></div></blockquote><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 4, 2013 at 2:21 AM, Duzy Chan <span dir="ltr"><<a href="mailto:geek@duzy.info" target="_blank">geek@duzy.info</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Honestly I'm not very sure about the real cause. I think it might have failed to request some resources. I added many locks for many situation (my latest code is at <a href="https://github.com/duzy/gst-switch" target="_blank">https://github.com/duzy/gst-switch</a>), and changed a method of log messages, refactored my code a lot, and <span style="font-family:arial,sans-serif;font-size:13px"><b>gst_bus_create_watch</b> issue seems gone</span>. But I'm now confronting another issue, complaining:</div>


<div><br></div><div><div><font color="#666666">(gst-switch-srv:1709): GLib-ERROR **: <b>Creating pipes for GWakeup: Too many open files</b></font></div></div><div><br></div><div>This is happened almost 100% percent, by running the a test for nearly 2 minutes. And this test was trying to make request to <b>gst-switch-srv</b> indirectly to recreate the pipelines repeatedly and very fast (I spawned three threads in the test for making the requests to the server, and it will at least recreate three pipelines in a request).</div>


<div><br></div><div>Everything looks fine, except for the <b>too-many-open-files</b> error. And this time my stack looks like this (the latest changes):</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">


<div><div><font color="#666666"><b>bt</b></font></div><div><font color="#666666">#0  <b>g_logv</b> (log_domain=0x7ffff72d11ae "GLib", log_level=G_LOG_LEVEL_ERROR, format=<optimized out>, args=args@entry=0x7fffffffddb8) at /build/buildd/glib2.0-2.34.1/./glib/gmessages.c:974</font></div>


<div><font color="#666666">#1  0x00007ffff7297e42 in <b>g_log</b> (log_domain=log_domain@entry=0x7ffff72d11ae "GLib", log_level=log_level@entry=G_LOG_LEVEL_ERROR, format=format@entry=0x7ffff7323030 "Creating pipes for GWakeup: %s\n") at /build/buildd/glib2.0-2.34.1/./glib/gmessages.c:1003</font></div>


<div><font color="#666666">#2  0x00007ffff72cd113 in <b>g_wakeup_new</b> () at /build/buildd/glib2.0-2.34.1/./glib/gwakeup.c:163</font></div><div><font color="#666666">#3  0x00007ffff728ed47 in <b>g_main_context_new</b> () at /build/buildd/glib2.0-2.34.1/./glib/gmain.c:590</font></div>


<div><font color="#666666">#4  0x00007fffd1cb1071 in <b>gst_multi_socket_sink_start_pre</b> (mhsink=0x23564d0) at gstmultisocketsink.c:1005</font></div><div><font color="#666666">#5  0x00007fffd1cacc50 in <b>gst_multi_handle_sink_start</b> (bsink=0x23564d0) at gstmultihandlesink.c:2112</font></div>


<div><font color="#666666">#6  <b>gst_multi_handle_sink_change_state</b> (element=0x23564d0, transition=<optimized out>) at gstmultihandlesink.c:2205</font></div><div><font color="#666666">#7  0x00007ffff7b2e28c in <b>gst_element_change_state</b> (element=element@entry=0x23564d0, transition=<optimized out>) at gstelement.c:2594</font></div>


<div><font color="#666666">#8  0x00007ffff7b2ec61 in <b>gst_element_set_state_func</b> (element=0x23564d0, state=GST_STATE_READY) at gstelement.c:2550</font></div><div><font color="#666666">#9  0x00007ffff7b16579 in <b>gst_bin_element_set_state</b> (next=GST_STATE_READY, current=GST_STATE_NULL, start_time=0, base_time=0, element=0x23564d0, bin=0x217f1b0) at gstbin.c:2308</font></div>


<div><font color="#666666">#10 <b>gst_bin_change_state_func</b> (element=0x217f1b0, transition=GST_STATE_CHANGE_NULL_TO_READY) at gstbin.c:2610</font></div><div><font color="#666666">#11 0x00007ffff7b2e28c in <b>gst_element_change_state</b> (element=element@entry=0x217f1b0, transition=<optimized out>) at gstelement.c:2594</font></div>


<div><font color="#666666">#12 0x00007ffff7b2ec61 in <b>gst_element_set_state_func</b> (element=0x217f1b0, state=GST_STATE_READY) at gstelement.c:2550</font></div><div><font color="#666666">#13 0x0000000000405961 in <b>gst_worker_start</b> (worker=0x62f0f0) at gstworker.c:236</font></div>


<div><font color="#666666">#14 0x000000000040bc30 in <b>gst_composite_close_transition</b> (composite=0x706800) at gstcomposite.c:513</font></div><div><font color="#666666">#15 <b>gst_composite_alive</b> (composite=0x706800) at gstcomposite.c:565</font></div>


<div><font color="#666666">#16 0x00000000004063ca in <b>gst_worker_state_paused_to_playing</b> (worker=0x706800) at gstworker.c:412</font></div><div><font color="#666666">#17 <b>gst_worker_pipeline_state_changed</b> (statechange=<optimized out>, worker=0x706800) at gstworker.c:463</font></div>


<div><font color="#666666">#18 <b>gst_worker_message</b> (bus=<optimized out>, message=0x7fffd80138a0, worker=0x706800) at gstworker.c:542</font></div><div><font color="#666666">#19 0x00007ffff7b1dc67 in <b>gst_bus_source_dispatch</b> (source=source@entry=0x23614f0, callback=0x405b40 <gst_worker_message>, user_data=0x706800) at gstbus.c:773</font></div>


<div><font color="#666666">#20 0x00007ffff7290ab5 in <b>g_main_dispatch</b> (context=0x61f2d0) at /build/buildd/glib2.0-2.34.1/./glib/gmain.c:2715</font></div><div><font color="#666666">#21 <b>g_main_context_dispatch</b> (context=context@entry=0x61f2d0) at /build/buildd/glib2.0-2.34.1/./glib/gmain.c:3219</font></div>


<div><font color="#666666">#22 0x00007ffff7290de8 in <b>g_main_context_iterate</b> (context=0x61f2d0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at /build/buildd/glib2.0-2.34.1/./glib/gmain.c:3290</font></div>


<div><font color="#666666">#23 0x00007ffff72911e2 in <b>g_main_loop_run</b> (loop=0x706760) at /build/buildd/glib2.0-2.34.1/./glib/gmain.c:3484</font></div><div><font color="#666666">#24 0x00000000004044c0 in <b>gst_switch_server_run</b> (srv=0x708000) at gstswitchserver.c:1095</font></div>


<div><font color="#666666">#25 <b>main</b> (argc=1, argv=0x7fffffffe578) at gstswitchserver.c:1119</font></div><div><br></div></div></blockquote></div><div>The top several call frames are almost 100% percent path. And the key location of my client code is at:</div>


<div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><a href="https://github.com/duzy/gst-switch/blob/switch/tools/gstworker.c#L681" target="_blank">https://github.com/duzy/gst-switch/blob/switch/tools/gstworker.c#L681</a><br>


</div><div><br></div></div></blockquote>Which is doing recreation of three pipelines. I've been tracking on it for some days, but not yet have found the exact cause point. But I'm very sure that those leaked file descriptors are all of "unix socket" class, and should be created by <b>g_unix_open_pipe</b>. E.g. those already opened files (part, total 1024):<div>


<br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>....</div><div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 750 -> socket:[2418126]</div><div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 751 -> socket:[2418138]</div>


<div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 752 -> socket:[2418139]</div><div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 753 -> socket:[2418140]</div><div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 754 -> socket:[2417418]</div>


<div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 755 -> socket:[2417357]</div><div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 756 -> socket:[2417358]</div><div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 757 -> socket:[2415573]</div>


<div>  lrwx------ 1 duzy duzy 64 Feb  4 01:46 758 -> socket:[2415574]</div><div>....</div><div><br></div></div></blockquote>I'm now think that if my previous issue was actually not solved, and that's actually very much related to too-many-open-files issue. Say:</div>


<div><br></div><div><div class="im"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div style="font-family:arial,sans-serif;font-size:13px">GStreamer-CRITICAL **: gst_poll_get_read_gpollfd: assertion `set != NULL' failed</div>


<div style="font-family:arial,sans-serif;font-size:13px">GStreamer-CRITICAL **: gst_bus_create_watch: assertion `bus->priv->poll != NULL' failed<br></div><div style="font-family:arial,sans-serif;font-size:13px">


GLib-CRITICAL **: g_source_set_callback: assertion `source != NULL' failed</div></div></blockquote><div><br></div></div><div>Hope you would have some ideas.</div><div><br></div><div>Best Regards</div><span class="HOEnZb"><font color="#888888">
<div>Duzy Chan</div><div><br></div></font></span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jan 26, 2013 at 7:50 PM, Tim-Philipp Müller <span dir="ltr"><<a href="mailto:t.i.m@zen.co.uk" target="_blank">t.i.m@zen.co.uk</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, 2013-01-26 at 08:08 +0800, Duzy Chan wrote:<br>
<br>
> Problem solved. Thanks all.<br>
<br>
So what was the problem/solution? Something in your code?<br>
<br>
 Cheers<br>
  -Tim<br>
<br>
<br>
<br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>