After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 767021 - RTSP server won't be destroyed until media is pre-rolled (or 20s timeout)
RTSP server won't be destroyed until media is pre-rolled (or 20s timeout)
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-rtsp-server
unspecified
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 750111
Blocks:
 
 
Reported: 2016-05-30 13:15 UTC by Xavier Claessens
Modified: 2018-11-03 15:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test case (2.05 KB, text/x-csrc)
2016-05-30 13:15 UTC, Xavier Claessens
  Details
Add gst_rtsp_server_shutdown() (10.26 KB, patch)
2016-06-02 13:39 UTC, Xavier Claessens
none Details | Review
Add gst_rtsp_server_shutdown() (10.67 KB, patch)
2016-06-02 17:16 UTC, Xavier Claessens
needs-work Details | Review

Description Xavier Claessens 2016-05-30 13:15:27 UTC
Created attachment 328727 [details]
test case

My application has an RTSP server that can be started/stopped by the user. When shutting down the server, I disconnect all clients, unref the server, and call gst_rtsp_thread_pool_cleanup() to be sure all resources has been cleaned.

If a client connects just before I stop the server, it will wait for pre-roll in gst_rtsp_media_get_status(). If pre-roll never happens it will unblock on a 20s timeout.

I think in the case that the client disconnects, it should unblock that condition.
Comment 1 Xavier Claessens 2016-05-31 17:58:36 UTC
Hm, looks like g_source_destroy() on the RTSP server's source fix my problem. Probably because it prevents new clients to connect while I'm trying to shutdown the server.

Maybe a proper gst_rtsp_server_shutdown() method could help dealing with that case.
Comment 2 Xavier Claessens 2016-05-31 18:16:24 UTC
Actually just got a crash with that backtrace, while a thread was inside gst_rtsp_thread_pool_cleanup():

  • #0 default_get_thread
    at rtsp-thread-pool.c line 496
  • #1 find_media
    at rtsp-client.c line 695
  • #2 handle_describe_request
    at rtsp-client.c line 2227
  • #3 handle_request
    at rtsp-client.c line 2884
  • #4 gst_rtsp_client_handle_message
    at rtsp-client.c line 3474
  • #5 gst_rtsp_source_dispatch_read
    at gstrtspconnection.c line 3368
  • #6 g_main_dispatch
    at gmain.c line 3237
  • #7 g_main_context_dispatch
    at gmain.c line 3898
  • #8 g_main_context_iterate
    at gmain.c line 3969
  • #9 g_main_loop_run
    at gmain.c line 4163
  • #10 do_loop
    at rtsp-thread-pool.c line 329
  • #11 g_thread_pool_thread_proxy
    at gthreadpool.c line 307
  • #12 g_thread_proxy
    at gthread.c line 778

Comment 3 Xavier Claessens 2016-06-02 13:39:53 UTC
Created attachment 328955 [details] [review]
Add gst_rtsp_server_shutdown()

When shutting down an RTSP server, a client could be in the process of
connecting, preparing its media, etc.

Most importantly, the client could be blocking waiting for the media pre-roll.
To unblock that situation, the client becomes responsible to call _unprepare()
on its media as soon as it reached the "preparing" state.
Comment 4 Xavier Claessens 2016-06-02 14:02:11 UTC
Context: I'm writing an (android) application that let the user start/stop sharing his webcam over RTSP. When the user stops the RTSP server I want to free all resources it takes, so I would like to call gst_rtsp_thread_pool_cleanup().

Wihtout this patch it is racy, because after calling gst_rtsp_client_close() on all existing clients, one of them could be in the middle of the process of preparing its media. For example it could be in find_media(), just before doing gst_rtsp_thread_pool_get_thread(). If gst_rtsp_thread_pool_cleanup() comes first, then the client push a thread in the pool, it crash.

Also a client could be blocking in wait_preroll(), and since I'm shutting down my pipeline, chances are it will never reach the PAUSED state and thus block in waiting preroll until a 20s timeout. The patch fix that case by calling gst_rtsp_media_unprepare() on preparing medias when their client gets closed.


Note that I'm *really* unsure if I'm doing it right, this is the first time I touch rtsp-server code. At least in my use case I couldn't reproduce crash/freeze anymore...
Comment 5 Xavier Claessens 2016-06-02 17:16:29 UTC
Created attachment 328984 [details] [review]
Add gst_rtsp_server_shutdown()

When shutting down an RTSP server, a client could be in the process of
connecting, preparing its media, etc.

Most importantly, the client could be blocking waiting for the media pre-roll.
To unblock that situation, the client becomes responsible to call _unprepare()
on its media as soon as it reached the "preparing" state.
Comment 6 Xavier Claessens 2016-10-13 13:07:16 UTC
Proposed patch uses the "preparing" signal added in the patch proposed for bug #750111
Comment 7 Sebastian Dröge (slomo) 2016-10-20 10:43:13 UTC
Review of attachment 328984 [details] [review]:

::: gst/rtsp-server/rtsp-media.c
@@ +3011,3 @@
+  if (priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARED ||
+      priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARING ||
+      priv->status == GST_RTSP_MEDIA_STATUS_ERROR)

In UNPREPARING we should probably wait? And in ERROR there might still be something to shut down

::: gst/rtsp-server/rtsp-server.c
@@ +1478,3 @@
+ * gst_rtsp_thread_pool_cleanup().
+ *
+ * Since: 1.10

Since: 1.12 :)
Comment 8 GStreamer system administrator 2018-11-03 15:39:57 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/issues/22.