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 698410 - Adder: Can not send flush_start and flush_stop in a row
Adder: Can not send flush_start and flush_stop in a row
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.x
Other Linux
: Normal normal
: 1.1.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-04-19 21:34 UTC by Thibault Saunier
Modified: 2013-05-02 11:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
First try at fixing the issue (4.61 KB, patch)
2013-04-19 21:34 UTC, Thibault Saunier
committed Details | Review
Fix the last observed issue (1.77 KB, patch)
2013-04-28 18:15 UTC, Thibault Saunier
none Details | Review
New patch removing now useless atomic operations (1.92 KB, patch)
2013-04-29 10:02 UTC, Thibault Saunier
none Details | Review
Remove the remaining atomic operations and take the STREAMING_LOCK where necessary (3.11 KB, patch)
2013-04-29 20:05 UTC, Thibault Saunier
accepted-commit_now Details | Review

Description Thibault Saunier 2013-04-19 21:34:07 UTC
Currently we are waiting for a SEGMENT_EVENT before accepting a FLUSH_STOP event. That can't happen as pads that are set to flushing will not accept any segement event.

I attach here a patch that fixes that issue, I am not sure what that need_flush_stop field was supposed to do exactly so I am unsure if it is the proper fix.
Comment 1 Thibault Saunier 2013-04-19 21:34:53 UTC
Created attachment 241956 [details] [review]
First try at fixing the issue
Comment 2 Tim-Philipp Müller 2013-04-19 21:57:42 UTC
Any chance you could add a unit test that fails without the patch too?
Comment 3 Thibault Saunier 2013-04-20 12:45:26 UTC
It does! without the patch I am getting:

thiblahute@Thibault-laptop ~/devel/pitivi/1.0-uninstalled/base/tests/check ((no branch)) $ GST_CHECKS=test_flush_start_flush_stop make elements/adder.check
Running suite(s): adder
0%: Checks: 1, Failures: 1, Errors: 0
elements/adder.c:1238:F:general:test_flush_start_flush_stop:0: Failure 'GST_PAD_IS_FLUSHING (adder_src)' occured
Running suite(s): adder
0%: Checks: 1, Failures: 1, Errors: 0
elements/adder.c:1238:F:general:test_flush_start_flush_stop:0: Failure 'GST_PAD_IS_FLUSHING (adder_src)' occured
make: *** [elements/adder.check] Error 1
Comment 4 Tim-Philipp Müller 2013-04-20 12:54:48 UTC
Sorry, I hadn't actually looked at the patch, so didn't see that it already contains a test :)
Comment 5 Stefan Sauer (gstreamer, gtkdoc dev) 2013-04-20 17:26:14 UTC
Trying it now.
Comment 6 Stefan Sauer (gstreamer, gtkdoc dev) 2013-04-21 14:12:04 UTC
Comment on attachment 241956 [details] [review]
First try at fixing the issue

Thanks!
Comment 7 Tim-Philipp Müller 2013-04-24 12:11:52 UTC
The unit test fails for me randomly:

$ GST_CHECKS=test_flush_start_flush_stop make elements/adder.forever
Running suite(s): adder
100%: Checks: 1, Failures: 0, Errors: 0
Running suite(s): adder
0%: Checks: 1, Failures: 1, Errors: 0
elements/adder.c:1236:F:general:test_flush_start_flush_stop:0: Assertion 'GST_PAD_IS_FLUSHING (adder_src)' failed

Very easy to reproduce here.

Also, could you in future please git commit --amend your commits/patches to include the bug number or link, thanks!
Comment 8 Thibault Saunier 2013-04-27 14:24:11 UTC
Ok, just managed to reproduce with a while loop (after 15 iteration) I will investigate that.

Really sorry for not adding the fix #X just that I did not think my patch would be merge right away.
Comment 9 Thibault Saunier 2013-04-27 16:52:48 UTC
OK so I investigated and the race is the following:

In the test: We send the flush_start
Thread 1: The adder sinkpads receives it and set the flush_stop_pending to TRUE
Thread 2: The adder has received buffers on all its sinkpads so collectpad calls gst_adder_collected, flush_stop_pending is set to TRUE so it creates and sends a flush_stop event on adder.src and sets flush_stop_pending to FALSE
          > adder.src.flushing = FALSE
Thread 1: We finaly send our flush_start event downstream
          > adder.src.flushing = TRUE
In the test: We send flush_stop
Thread 1 - Adder detects that flush_stop_pending is FALSE so it "eats" the event

I do not really get how that should be fixed without using plain locks, any guess?
Comment 10 Thibault Saunier 2013-04-28 18:15:27 UTC
Created attachment 242741 [details] [review]
Fix the last observed issue

I figured that we need to take the streaming thread of collectpad to ensure that the ->collected vmethod won't get called while we forward the flush event.
Comment 11 Sebastian Dröge (slomo) 2013-04-29 09:11:11 UTC
Does this fix all of it? It looks sensible but if you add a lock there anyway you can get rid of the atomic operations that were added there exactly because of bugs like this one :)
Comment 12 Thibault Saunier 2013-04-29 10:02:56 UTC
Created attachment 242787 [details] [review]
New patch removing now useless atomic operations
Comment 13 Sebastian Dröge (slomo) 2013-04-29 10:10:41 UTC
Are atomic ops still used for the adder->*pending fields elsewhere? If not this is good to be pushed I guess
Comment 14 Thibault Saunier 2013-04-29 20:05:53 UTC
Created attachment 242838 [details] [review]
Remove the remaining atomic operations and take the STREAMING_LOCK where necessary
Comment 15 Sebastian Dröge (slomo) 2013-04-29 20:07:46 UTC
Thanks, looks good to me. To check if this is bulletproof, please ask Stefan on IRC if he can test it in buzztard :) He's also CC'd here
Comment 16 Stefan Sauer (gstreamer, gtkdoc dev) 2013-04-30 11:43:46 UTC
+1, tried the patch and works for me. Thanks for waiting.
Comment 17 Nicolas Dufresne (ndufresne) 2013-04-30 14:01:08 UTC
Review of attachment 242838 [details] [review]:

::: gst/adder/gstadder.c
@@ +822,3 @@
     case GST_EVENT_FLUSH_START:
       /* ensure that we will send a flush stop */
+      GST_COLLECT_PADS_STREAM_LOCK (adder->collect);

I'm just curious, with normal pad, we can't take stream lock to send a flush-start, does collect pads stream lock endup taking pads stream lock ?
Comment 18 Thibault Saunier 2013-05-01 15:34:56 UTC
The collectpad STREAM_LOCK is a special lock from collectpad, it is not related to pad stream's lock.

slomo: Is it good enough to merge then?
Comment 19 Sebastian Dröge (slomo) 2013-05-02 07:25:39 UTC
Yes
Comment 20 Thibault Saunier 2013-05-02 11:31:20 UTC
commit 372eddf00e9496a558472e197ec6880663092c14
Author: Thibault Saunier <thibault.saunier@collabora.com>
Date:   Sun Apr 28 20:07:47 2013 +0200

    adder: Get collectpad stream lock when fowarding flush events
    
    Fixes #698410