Bug 204565 - Queuing a task in EventLoop is not working with UserMediaRequest allow completion handler
Summary: Queuing a task in EventLoop is not working with UserMediaRequest allow comple...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-11-24 23:18 PST by youenn fablet
Modified: 2019-11-26 00:30 PST (History)
13 users (show)

See Also:


Attachments
Patch (4.03 KB, patch)
2019-11-25 00:29 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2019-11-24 23:18:01 PST
As can be seen from https://build.webkit.org/results/Apple-Catalina-Debug-WK2-Tests/r252843%20(823)/results.html, completion handlers given to UserMediaRequest::allow are not always called.
ASSERTION FAILED: Completion handler should always be called
!m_function
/Volumes/Data/slave/catalina-debug/build/WebKitBuild/Debug/usr/local/include/wtf/CompletionHandler.h(53) : WTF::CompletionHandler<void ()>::~CompletionHandler()
1   0x4ab785659 WTFCrash
2   0x490e086b3 WTF::CompletionHandler<void ()>::~CompletionHandler()
3   0x490e08645 WTF::CompletionHandler<void ()>::~CompletionHandler()
4   0x492af75e3 WebCore::UserMediaRequest::allow(WebCore::CaptureDevice&&, WebCore::CaptureDevice&&, WTF::String&&, WTF::CompletionHandler<void ()>&&)::$_2::~$_2()
5   0x492af43d5 WebCore::UserMediaRequest::allow(WebCore::CaptureDevice&&, WebCore::CaptureDevice&&, WTF::String&&, WTF::CompletionHandler<void ()>&&)::$_2::~$_2()
6   0x492b01511 WTF::Detail::CallableWrapper<WebCore::UserMediaRequest::allow(WebCore::CaptureDevice&&, WebCore::CaptureDevice&&, WTF::String&&, WTF::CompletionHandler<void ()>&&)::$_2, void>::~CallableWrapper()
7   0x492b013f5 WTF::Detail::CallableWrapper<WebCore::UserMediaRequest::allow(WebCore::CaptureDevice&&, WebCore::CaptureDevice&&, WTF::String&&, WTF::CompletionHandler<void ()>&&)::$_2, void>::~CallableWrapper()
8   0x492b01419 WTF::Detail::CallableWrapper<WebCore::UserMediaRequest::allow(WebCore::CaptureDevice&&, WebCore::CaptureDevice&&, WTF::String&&, WTF::CompletionHandler<void ()>&&)::$_2, void>::~CallableWrapper()
9   0x490da79ff std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> >::operator()(WTF::Detail::CallableWrapperBase<void>*) const
10  0x490da79bf std::__1::unique_ptr<WTF::Detail::CallableWrapperBase<void>, std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> > >::reset(WTF::Detail::CallableWrapperBase<void>*)
11  0x490da7959 std::__1::unique_ptr<WTF::Detail::CallableWrapperBase<void>, std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> > >::~unique_ptr()
12  0x490da7935 std::__1::unique_ptr<WTF::Detail::CallableWrapperBase<void>, std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> > >::~unique_ptr()
13  0x490da7915 WTF::Function<void ()>::~Function()
14  0x490da78f5 WTF::Function<void ()>::~Function()
15  0x492b00f13 void WebCore::ActiveDOMObject::queueTaskKeepingObjectAlive<WebCore::UserMediaRequest>(WebCore::UserMediaRequest&, WebCore::TaskSource, WTF::Function<void ()>&&)::'lambda'()::~()
16  0x492b00105 void WebCore::ActiveDOMObject::queueTaskKeepingObjectAlive<WebCore::UserMediaRequest>(WebCore::UserMediaRequest&, WebCore::TaskSource, WTF::Function<void ()>&&)::'lambda'()::~()
17  0x492b00a41 WTF::Detail::CallableWrapper<void WebCore::ActiveDOMObject::queueTaskKeepingObjectAlive<WebCore::UserMediaRequest>(WebCore::UserMediaRequest&, WebCore::TaskSource, WTF::Function<void ()>&&)::'lambda'(), void>::~CallableWrapper()
18  0x492b00585 WTF::Detail::CallableWrapper<void WebCore::ActiveDOMObject::queueTaskKeepingObjectAlive<WebCore::UserMediaRequest>(WebCore::UserMediaRequest&, WebCore::TaskSource, WTF::Function<void ()>&&)::'lambda'(), void>::~CallableWrapper()
19  0x492b005a9 WTF::Detail::CallableWrapper<void WebCore::ActiveDOMObject::queueTaskKeepingObjectAlive<WebCore::UserMediaRequest>(WebCore::UserMediaRequest&, WebCore::TaskSource, WTF::Function<void ()>&&)::'lambda'(), void>::~CallableWrapper()
20  0x490da79ff std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> >::operator()(WTF::Detail::CallableWrapperBase<void>*) const
21  0x490da79bf std::__1::unique_ptr<WTF::Detail::CallableWrapperBase<void>, std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> > >::reset(WTF::Detail::CallableWrapperBase<void>*)
22  0x490da7959 std::__1::unique_ptr<WTF::Detail::CallableWrapperBase<void>, std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> > >::~unique_ptr()
23  0x490da7935 std::__1::unique_ptr<WTF::Detail::CallableWrapperBase<void>, std::__1::default_delete<WTF::Detail::CallableWrapperBase<void> > >::~unique_ptr()
24  0x490da7915 WTF::Function<void ()>::~Function()
25  0x490da78f5 WTF::Function<void ()>::~Function()
26  0x49368c561 WebCore::EventLoopFunctionDispatchTask::~EventLoopFunctionDispatchTask()
27  0x49368bbc5 WebCore::EventLoopFunctionDispatchTask::~EventLoopFunctionDispatchTask()
28  0x49368bbe9 WebCore::EventLoopFunctionDispatchTask::~EventLoopFunctionDispatchTask()
29  0x4936971df std::__1::default_delete<WebCore::EventLoopTask>::operator()(WebCore::EventLoopTask*) const
30  0x49369719f std::__1::unique_ptr<WebCore::EventLoopTask, std::__1::default_delete<WebCore::EventLoopTask> >::reset(WebCore::EventLoopTask*)
31  0x493697139 std::__1::unique_ptr<WebCore::EventLoopTask, std::__1::default_delete<WebCore::EventLoopTask> >::~unique_ptr()
LEAK: 1 WebPageProxy
Comment 1 Radar WebKit Bug Importer 2019-11-24 23:18:22 PST
<rdar://problem/57466280>
Comment 2 youenn fablet 2019-11-25 00:29:41 PST
Created attachment 384277 [details]
Patch
Comment 3 Ryosuke Niwa 2019-11-25 13:57:38 PST
Comment on attachment 384277 [details]
Patch

Interesting. I wonder if this is a common pattern. If so, we can add a variant of queueTaskKeepingObjectAlive which takes a completion handler & automatically calls it in the case the task is dropped because the event loop knows when an active DOM object is stopped.
Comment 4 youenn fablet 2019-11-25 23:47:05 PST
(In reply to Ryosuke Niwa from comment #3)
> Comment on attachment 384277 [details]
> Patch
> 
> Interesting. I wonder if this is a common pattern. If so, we can add a
> variant of queueTaskKeepingObjectAlive which takes a completion handler &
> automatically calls it in the case the task is dropped because the event
> loop knows when an active DOM object is stopped.

I did a grep of queueTaskKeepingObjectAlive and completionHandler and only found this place, hence the change of bug title and current patch.
If we run in the same issue in the future, we might indeed try to find a better solution.
Comment 5 WebKit Commit Bot 2019-11-26 00:30:48 PST
Comment on attachment 384277 [details]
Patch

Clearing flags on attachment: 384277

Committed r252878: <https://trac.webkit.org/changeset/252878>
Comment 6 WebKit Commit Bot 2019-11-26 00:30:50 PST
All reviewed patches have been landed.  Closing bug.