Skip to content

adaptivedemux2: Do not submit_transfer when cancelled

There is a race condition where transfer has not been submitted yet while the request is cancelled which leads to the transfer state going back to DOWNLOAD_REQUEST_STATE_OPEN and the user of the request to get signalled about its completion (and the task actually happening after it was cancelled) leading to assertions and misbehaviours.

To ensure that this race can't happen, we start differentiating between the UNSENT and CANCELLED states as in the normal case, when entering submit_request the state is UNSENT and at that point we need to know that it is not because the request has been cancelled.

In practice this case lead to an assertion in gst_adaptive_demux2_stream_begin_download_uri because in a previous call to gst_adaptive_demux2_stream_stop_default we cancelled the previous request and setup a new one while it had not been submitted yet and then got a on_download_complete callback called from that previous cancelled request and then we tried to do download_request_set_uri on a request that was still in_use, leading to something like:

 thread #75, name = 'AdaptiveDemux'
    frame #0: 0x0000000186655ec8 g_assert (request->in_use == FALSE)
    frame #1: 0x00000001127236b8 libgstadaptivedemux2.dylib`download_request_set_uri(request=0x000060000017cc00, uri="https://XXX/chunk-stream1-00002.webm", range_start=0, range_end=-1) at downloadrequest.c:361:5 [opt]
    frame #2: 0x000000011271cee8 libgstadaptivedemux2.dylib`gst_adaptive_demux2_stream_begin_download_uri(stream=0x00000001330f1800, uri="https://XXX/chunk-stream1-00002.webm", start=0, end=-1) at gstadaptivedemux-stream.c:1447:3 [opt]
    frame #3: 0x0000000112719898 libgstadaptivedemux2.dylib`gst_adaptive_demux2_stream_load_a_fragment [inlined] gst_adaptive_demux2_stream_download_fragment(stream=0x00000001330f1800) at gstadaptivedemux-stream.c:0 [opt]
    frame #4: 0x00000001127197f8 libgstadaptivedemux2.dylib`gst_adaptive_demux2_stream_load_a_fragment(stream=0x00000001330f1800) at gstadaptivedemux-stream.c:1969:11 [opt]
    frame #5: 0x000000011271c2a4 libgstadaptivedemux2.dylib`gst_adaptive_demux2_stream_next_download(stream=0x00000001330f1800) at gstadaptivedemux-stream.c:2112:10 [opt]
    frame #6: 0x0000000105751d68 libglib-2.0.0.dylib`g_main_context_dispatch + 256
    frame #7: 0x0000000105752088 libglib-2.0.0.dylib`g_main_context_iterate + 436
    frame #8: 0x00000001057523a8 libglib-2.0.0.dylib`g_main_loop_run + 268
    frame #9: 0x0000000112715c8c libgstadaptivedemux2.dylib`_gst_adaptive_demux_loop_thread(loop=0x000060000179ac60) at gstadaptivedemuxutils.c:204:5 [opt]
    frame #10: 0x0000000105778220 libglib-2.0.0.dylib`g_thread_proxy + 68
    frame #11: 0x0000000186693034 libsystem_pthread.dylib`_pthread_start + 136
Edited by Thibault Saunier

Merge request reports

Loading