WebPlatformForEmbedded / WPEWebKit

WPE WebKit port (downstream)
211 stars 135 forks source link

[wpe-2.38] Cancel all async tasks scheduled on destruction #1231

Closed varumugam123 closed 8 months ago

varumugam123 commented 9 months ago

Problem: On launching HBOMax app on Comcast STBs (user is already logged into the app) app plays a ~4 second video and on completion destructs the pipeline. Soon after that there is a crash with below signature

Version : wpe-2.38 (39d3d180b2)

#0  std::__exchange<WebCore::AbortableTaskQueue::Task*, decltype(nullptr)&>(WebCore::AbortableTaskQueue::Task*&, decltype(nullptr)&) () at ../recipe-sysroot/usr/include/c++/9.3.0/bits/move.h:151
#1  std::exchange<WebCore::AbortableTaskQueue::Task*, decltype(nullptr)&>(WebCore::AbortableTaskQueue::Task*&, decltype(nullptr)&) () at ../recipe-sysroot/usr/include/c++/9.3.0/utility:287
#2  WTF::RawPtrTraits<WebCore::AbortableTaskQueue::Task>::exchange<decltype(nullptr)>(WebCore::AbortableTaskQueue::Task*&, decltype(nullptr)&&) () at WTF/Headers/wtf/RawPtrTraits.h:41
#3  WTF::Ref<WebCore::AbortableTaskQueue::Task, WTF::RawPtrTraits<WebCore::AbortableTaskQueue::Task> >::~Ref () at WTF/Headers/wtf/Ref.h:60
#4  WTF::VectorDestructor<true, WTF::Ref<WebCore::AbortableTaskQueue::Task, WTF::RawPtrTraits<WebCore::AbortableTaskQueue::Task> > >::destruct () at WTF/Headers/wtf/Vector.h:69
#5  WTF::VectorTypeOperations<WTF::Ref<WebCore::AbortableTaskQueue::Task, WTF::RawPtrTraits<WebCore::AbortableTaskQueue::Task> > >::destruct () at WTF/Headers/wtf/Vector.h:252
#6  WTF::Deque<WTF::Ref<WebCore::AbortableTaskQueue::Task, WTF::RawPtrTraits<WebCore::AbortableTaskQueue::Task> >, 0u>::removeFirst () at WTF/Headers/wtf/Deque.h:503
#7  WebCore::AbortableTaskQueue::Task::dispatch () at ../git/Source/WebCore/platform/AbortableTaskQueue.h:204
#8  WebCore::AbortableTaskQueue::postTask(WTF::Function<void ()>&&)::{lambda()#1}::operator()() const () at ../git/Source/WebCore/platform/AbortableTaskQueue.h:223
#9  WTF::Detail::CallableWrapper<WebCore::AbortableTaskQueue::postTask(WTF::Function<void ()>&&)::{lambda()#1}, void>::call() () at WTF/Headers/wtf/Function.h:53
#10 0xb25a0732 in WTF::Function<void ()>::operator()() const () at ../git/Source/WTF/wtf/Function.h:82
#11 WTF::RunLoop::performWork () at ../git/Source/WTF/wtf/RunLoop.cpp:134
#12 0xb25d7522 in operator() () at ../git/Source/WTF/wtf/glib/RunLoopGLib.cpp:80
#13 _FUN () at ../git/Source/WTF/wtf/glib/RunLoopGLib.cpp:82
#14 0xb25d7d70 in operator() () at ../git/Source/WTF/wtf/glib/RunLoopGLib.cpp:53
#15 _FUN () at ../git/Source/WTF/wtf/glib/RunLoopGLib.cpp:56
#16 0xb05cdbe8 in g_main_dispatch (context=0x7eb56638) at ../glib-2.62.4/glib/gmain.c:3216
#17 g_main_context_dispatch (context=context@entry=0x7eb56638) at ../glib-2.62.4/glib/gmain.c:3885
#18 0xb05cdd52 in g_main_context_iterate (context=0x7eb56638, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib-2.62.4/glib/gmain.c:3958
#19 0xb05ce08c in g_main_loop_run (loop=0x7eb57150) at ../glib-2.62.4/glib/gmain.c:4152
#20 0xb25d8010 in WTF::RunLoop::run () at ../git/Source/WTF/wtf/glib/RunLoopGLib.cpp:108
#21 0xb1d6c802 in WebKit::AuxiliaryProcessMainBase<WebKit::WebProcess, true>::run () at ../git/Source/WebKit/Shared/AuxiliaryProcessMain.h:71
#22 WebKit::AuxiliaryProcessMainBase<WebKit::WebProcess, true>::run () at ../git/Source/WebKit/Shared/AuxiliaryProcessMain.h:58
#23 WebKit::AuxiliaryProcessMain<WebKit::WebProcessMainWPE> () at ../git/Source/WebKit/Shared/AuxiliaryProcessMain.h:97
#24 0xb16b698e in __libc_start_main (main=0x7d60d545 <main()>, argc=3, argv=0xbbca0714, init=<optimized out>, fini=0x7d60d699 <__libc_csu_fini>, rtld_fini=0xb3f53099 <_dl_fini>, stack_end=0xbbca0714) at libc-start.c:308
#25 0x7d60d57c in _start () at start.S:112
2023 Oct 25 16:00:59.618058 LightningApp-0[4906]:  HTML5 video: Player constructed [0x9dd2a600]
2023 Oct 25 16:00:59.618193 LightningApp-0[4906]:  HTML5 video: Loading [https://<hbomaxurl>/outro.6de0c5915653eff4b2dc7648d3927ca0.sha.mp4]
2023 Oct 25 16:00:59.628863 LightningApp-0[4906]:  HTML5 video: Pause [https://<hbomaxurl>/outro.6de0c5915653eff4b2dc7648d3927ca0.sha.mp4]
...
2023 Oct 25 16:01:03.351752 LightningApp-0[4906]:  HTML5 video: Player Destroyed [0x9dd2a600]
...
2023 Oct 25 16:01:06.120051 LightningApp-0[4906]:  pid 8 has terminated (return code 1)
2023 Oct 25 16:01:06.125605 WPEFramework[6615]:  231025-16:01:06.121 [Warning] [tid=9092] OnPluginStateChange:Service.cpp:229 Service::OnPluginStateChange [LightningApp-0 - Deactivation, Failure]

It looks like the async task posted by MediaPlayerPrivateGStreamer->TrackPrivateBaseGStreamer on AbortableTaskQueue is dispatched after the Player is destructed. AbortableTaskQueue is composited inside TrackPrivateBaseGStreamer and gets destructed along with Player & TrackPrivateBase.

varumugam123 commented 9 months ago

I was able to reproduce the issue (delayed dispatch of async task post MediaPlayer destruction) with a test page. I confirmed it through custom logs as this simple test doesn't trigger crash. I suppose that is because even though the AbortableTaskQueue is destructed its remnants are still in memory for a period or atleast until the dispatch is done.

delayed-async-task-dispatch-simple.html.txt

Logs

Nov 11 04:36:14 hisense-a6gp WPEFramework[14507]: HTML5 video: Player constructed [0x9c661600]
Nov 11 04:36:14 hisense-a6gp WPEFramework[14507]: HTML5 video: Loading [http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4]
Nov 11 04:36:14 hisense-a6gp WPEFramework[14507]: HTML5 video: Pause [http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4]
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: TrackPrivateBaseGStreamer::operator() (0x9fca7304), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: AbortableTaskQueue::postTask, enqueuing task 0x9aad2000
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x9aad2000
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: TrackPrivateBaseGStreamer::operator() (0x9fca7304), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: AbortableTaskQueue::postTask, enqueuing task 0x9aad2010
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x9aad2010
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: TrackPrivateBaseGStreamer::operator() (0x9fca7304), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: AbortableTaskQueue::postTask, enqueuing task 0x9aad2020
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x9aad2020
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: TrackPrivateBaseGStreamer::operator() (0x9fca7304), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: AbortableTaskQueue::postTask, enqueuing task 0x9aad2030
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: TrackPrivateBaseGStreamer::operator() (0x9fca7304), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23508]: AbortableTaskQueue::postTask, enqueuing task 0x9aad2040
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x9aad2030
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x9aad2040
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: HTML5 video: Play [http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4]
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: HTML5 video: Playback started [http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4]
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07000
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07010
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07020
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07000
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07010
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07020
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07030
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07040
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07030
Nov 11 04:36:16 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07040
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07050
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07060
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07070
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07050
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07060
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07070
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07080
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07080
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::tags
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,23507]: AbortableTaskQueue::postTask, enqueuing task 0x98f07090
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x98f07090
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: [HtmlApp]:67 VIVEK-DBG: clearing video.src, to force media player destruction
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: HTML5 video: Playback terminated [http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4]
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: TrackPrivateBaseGStreamer::operator() (0x9fca7304), pad notify::caps
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::postTask, enqueuing task 0x933e6010
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: TrackPrivateBaseGStreamer::operator() (0x9f624684), pad notify::caps
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::postTask, enqueuing task 0x933e6020
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: HTML5 video: Player Destroyed [0x9c661600]
Nov 11 04:36:17 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: HTMLMediaElement::invalidateCachedTime (0xa2f6dea0), cachedTime is being invalidated here

Nov 11 04:36:24 hisense-a6gp WPEFramework[14507]: [HtmlApp]:74 VIVEK-DBG: cleared video.src, to force media player destruction
Nov 11 04:36:24 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x933e6010
Nov 11 04:36:24 hisense-a6gp WPEFramework[14507]: VIVEK-DBG [14974,14974]: AbortableTaskQueue::Task::dispatch, dispatched 0x933e6020
eocanha commented 8 months ago

Submitted this PR upstream for review as https://bugs.webkit.org/show_bug.cgi?id=266715 / https://github.com/WebKit/WebKit/pull/22120.

eocanha commented 8 months ago

Patch landed upstream as https://github.com/WebKit/WebKit/commit/b1393655168baaef5595d59edb774c0ba12bc8cd, backported to wpe-2.38 as https://github.com/WebPlatformForEmbedded/WPEWebKit/commit/88486196bd1e3513e117e192d659e6c73f750643 and to wpe-2.42 as https://github.com/WebPlatformForEmbedded/WPEWebKit/commit/5e9ca95e070484d95671990153de40473ac45ca6. Closing PR.

eocanha commented 8 months ago

New upstream PR https://github.com/WebKit/WebKit/pull/22253 submitted for review.

eocanha commented 8 months ago

Upstream commits https://github.com/WebKit/WebKit/commit/6248d02aae449c5c3986d13e9b252d56e4cd8a92 (revert) and https://github.com/WebKit/WebKit/commit/bda86858ca813149fbfc74acc73169ce0ac7c30b (fixed commit) backported to wpe-2.38 as https://github.com/WebPlatformForEmbedded/WPEWebKit/commit/15f95679a4515ae54c7b7397940eae3dcb7fb227 and https://github.com/WebPlatformForEmbedded/WPEWebKit/commit/7f261cd5c650b0a333f74eea38dcacc10830e0cc and to wpe-2.42 as https://github.com/WebPlatformForEmbedded/WPEWebKit/commit/cc83845e8205532d48667849cb767cc7cd341288 and https://github.com/WebPlatformForEmbedded/WPEWebKit/commit/ebf5645dd7ebaa6712a88bb7a6798e265fe41e89.