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 755342 - element: state_change may fail because of release_request_pad (racy)
element: state_change may fail because of release_request_pad (racy)
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
1.5.2
Other Linux
: Normal normal
: 1.6.0
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks: 755343
 
 
Reported: 2015-09-21 11:55 UTC by Stian Selnes (stianse)
Modified: 2015-09-24 10:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
element: Ignore activate result for removed pads on state change (1.40 KB, patch)
2015-09-21 13:43 UTC, Stian Selnes (stianse)
none Details | Review
bin: element: Ignore activate result for removed pads on state change (2.21 KB, patch)
2015-09-22 12:54 UTC, Stian Selnes (stianse)
committed Details | Review

Description Stian Selnes (stianse) 2015-09-21 11:55:52 UTC
gst_element_state_change() may unexpectedly fail if the element is releasing a request pad simultaneously.

gst_element_state_change() will iterate over the pads and activate/deactivate. If the timing is unfortunate and the pad is deactivated and removed (from release_pad function) after the iterator is created and while activate_pads() is called, gst_pad_set_active() may be called from activate_pads() on a pad with no parent causing gst_element_state_change() to return GST_STATE_CHANGE_FAILURE.

This may happen on both activation and deactivation from gst_element_state_change().

This behavior has changed since 0.10 since no parent was needed then.
Comment 1 Sebastian Dröge (slomo) 2015-09-21 12:06:12 UTC
I guess the solution would be to check afterwards if things fail if the pad is still a child of the element?
Comment 2 Stian Selnes (stianse) 2015-09-21 13:43:44 UTC
Created attachment 311752 [details] [review]
element: Ignore activate result for removed pads on state change

This fixes a race where gst_element_change_state() may return failure if
it has request pads that are deactivated and removed (and thus have no
parent) at the same time as the element changes state and (de)activates
its pads.
Comment 3 Sebastian Dröge (slomo) 2015-09-22 11:12:11 UTC
Review of attachment 311752 [details] [review]:

Looks good but

::: gst/gstelement.c
@@ +2691,3 @@
+    if (GST_PAD_PARENT (pad) != NULL) {
+      cont = FALSE;
+      g_value_set_boolean (ret, FALSE);

Same change needed in gstbin.c (search for gst_pad_set_active())
Comment 4 Stian Selnes (stianse) 2015-09-22 12:54:38 UTC
Created attachment 311854 [details] [review]
bin: element: Ignore activate result for removed pads on state change

This fixes a race where a state change may return failure if it has
request pads that are deactivated and removed (and thus have no
parent) at the same time as the element changes state and (de)activates
its pads.
Comment 5 Sebastian Dröge (slomo) 2015-09-24 10:15:08 UTC
commit 2c60b7eb1fc8851296e7bbb209663bb0c0e53f21
Author: Stian Selnes <stian@pexip.com>
Date:   Mon Sep 21 13:58:51 2015 +0200

    funnel: Fix racy state change
    
    Iterator may need to be resynced, for instance if pads are released
    during state change.
    
    got_eos should be protected by the object lock of the element, not of
    the pad, as is the case throughout the rest of the funnel code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755343