New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser: make destruction of webContents async #9113

Merged
merged 6 commits into from May 1, 2017

Conversation

Projects
None yet
2 participants
@deepak1556
Member

deepak1556 commented Apr 5, 2017

@deepak1556 deepak1556 requested review from kevinsawicki and zcbenz Apr 5, 2017

// FIXME: Multiple Emit calls inside an observer assume that object
// will be alive till end of the observer. Synchronous `destroy` api
// violates this contract and crashes.
// { name: 'did-frame-finish-load', url: `${server.url}/200` },

This comment has been minimized.

@deepak1556

deepak1556 Apr 5, 2017

Member

@zcbenz currently we have in api_web_contents.cc the following:

void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
                                const GURL& validated_url) {
  bool is_main_frame = !render_frame_host->GetParent();
  Emit("did-frame-finish-load", is_main_frame);

  if (is_main_frame)
    Emit("did-finish-load");
}

calling webContents.destroy inside did-frame-finish-load will lead to a crash when did-finish-load is invoked with

[2853:0404/235125.714735:FATAL:wrappable.cc(24)] Check failed: !wrapper_.IsEmpty(). 
#0 0x7fe05839616e base::debug::StackTrace::StackTrace()
#1 0x7fe0583b2eab logging::LogMessage::~LogMessage()
#2 0x000000b8d723 mate::WrappableBase::GetWrapper()
#3 0x000000c782e5 mate::EventEmitter<>::GetWrapper()
#4 0x000000c7b1f9 _ZN4mate12EventEmitterIN4atom3api11WebContentsEE14EmitWithSenderIJEEEbRKN4base16BasicStringPieceISsEEPN7content11WebContentsEPN3IPC7MessageEDpRKT_
#5 0x000000c71bf4 _ZN4mate12EventEmitterIN4atom3api11WebContentsEE4EmitIJEEEbRKN4base16BasicStringPieceISsEEDpRKT_
#6 0x000000c6761a atom::api::WebContents::DidFinishLoad()
#7 0x7fe05c397999 content::WebContentsImpl::OnDidFinishLoad()
#8 0x7fe05c39777e <unknown>
#9 0x7fe05c3963fc content::WebContentsImpl::OnMessageReceived()
#10 0x7fe05c121888 content::RenderFrameHostImpl::OnMessageReceived()
#11 0x7fe057edeac5 IPC::ChannelProxy::Context::OnDispatchMessage()
#12 0x7fe058396cee base::debug::TaskAnnotator::RunTask()
#13 0x7fe0583bba1c base::MessageLoop::RunTask()
#14 0x7fe0583bbd38 base::MessageLoop::DeferOrRunPendingTask()
#15 0x7fe0583bc0fb base::MessageLoop::DoWork()
#16 0x7fe0583be4aa <unknown>
#17 0x7fe0499835a7 g_main_context_dispatch
#18 0x7fe049983810 <unknown>
#19 0x7fe0499838bc g_main_context_iteration
#20 0x7fe0583be316 base::MessagePumpGlib::Run()
#21 0x7fe0583bb7b7 base::MessageLoop::RunHandler()
#22 0x7fe0583e52b0 base::RunLoop::Run()
#23 0x7fe05c03bab8 content::BrowserMainLoop::MainMessageLoopRun()
#24 0x7fe05c03b905 content::BrowserMainLoop::RunMainMessageLoopParts()
#25 0x7fe05c03e94d <unknown>
#26 0x7fe05c03743e content::BrowserMain()
#27 0x7fe05c6db094 <unknown>
#28 0x7fe05c6d9ba0 content::ContentMain()
#29 0x000000aa569a main
#30 0x7fe047ae9511 __libc_start_main
#31 0x000000aa54e5 <unknown>

I can think of two ways to fix this:

  • Make destroy async by default deepak1556/native-mate@c98d5d6 , will have to rewire cases inside the code base to follow this behavior, especially webview since we need to make sure they are destroyed before any host webContents.

  • Return empty wrapper when its destroyed and check if object is available before emitting events.

What can be the best approach to fix this scenario ?

@deepak1556

deepak1556 Apr 5, 2017

Member

@zcbenz currently we have in api_web_contents.cc the following:

void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
                                const GURL& validated_url) {
  bool is_main_frame = !render_frame_host->GetParent();
  Emit("did-frame-finish-load", is_main_frame);

  if (is_main_frame)
    Emit("did-finish-load");
}

calling webContents.destroy inside did-frame-finish-load will lead to a crash when did-finish-load is invoked with

[2853:0404/235125.714735:FATAL:wrappable.cc(24)] Check failed: !wrapper_.IsEmpty(). 
#0 0x7fe05839616e base::debug::StackTrace::StackTrace()
#1 0x7fe0583b2eab logging::LogMessage::~LogMessage()
#2 0x000000b8d723 mate::WrappableBase::GetWrapper()
#3 0x000000c782e5 mate::EventEmitter<>::GetWrapper()
#4 0x000000c7b1f9 _ZN4mate12EventEmitterIN4atom3api11WebContentsEE14EmitWithSenderIJEEEbRKN4base16BasicStringPieceISsEEPN7content11WebContentsEPN3IPC7MessageEDpRKT_
#5 0x000000c71bf4 _ZN4mate12EventEmitterIN4atom3api11WebContentsEE4EmitIJEEEbRKN4base16BasicStringPieceISsEEDpRKT_
#6 0x000000c6761a atom::api::WebContents::DidFinishLoad()
#7 0x7fe05c397999 content::WebContentsImpl::OnDidFinishLoad()
#8 0x7fe05c39777e <unknown>
#9 0x7fe05c3963fc content::WebContentsImpl::OnMessageReceived()
#10 0x7fe05c121888 content::RenderFrameHostImpl::OnMessageReceived()
#11 0x7fe057edeac5 IPC::ChannelProxy::Context::OnDispatchMessage()
#12 0x7fe058396cee base::debug::TaskAnnotator::RunTask()
#13 0x7fe0583bba1c base::MessageLoop::RunTask()
#14 0x7fe0583bbd38 base::MessageLoop::DeferOrRunPendingTask()
#15 0x7fe0583bc0fb base::MessageLoop::DoWork()
#16 0x7fe0583be4aa <unknown>
#17 0x7fe0499835a7 g_main_context_dispatch
#18 0x7fe049983810 <unknown>
#19 0x7fe0499838bc g_main_context_iteration
#20 0x7fe0583be316 base::MessagePumpGlib::Run()
#21 0x7fe0583bb7b7 base::MessageLoop::RunHandler()
#22 0x7fe0583e52b0 base::RunLoop::Run()
#23 0x7fe05c03bab8 content::BrowserMainLoop::MainMessageLoopRun()
#24 0x7fe05c03b905 content::BrowserMainLoop::RunMainMessageLoopParts()
#25 0x7fe05c03e94d <unknown>
#26 0x7fe05c03743e content::BrowserMain()
#27 0x7fe05c6db094 <unknown>
#28 0x7fe05c6d9ba0 content::ContentMain()
#29 0x000000aa569a main
#30 0x7fe047ae9511 __libc_start_main
#31 0x000000aa54e5 <unknown>

I can think of two ways to fix this:

  • Make destroy async by default deepak1556/native-mate@c98d5d6 , will have to rewire cases inside the code base to follow this behavior, especially webview since we need to make sure they are destroyed before any host webContents.

  • Return empty wrapper when its destroyed and check if object is available before emitting events.

What can be the best approach to fix this scenario ?

This comment has been minimized.

@zcbenz

zcbenz May 1, 2017

Contributor

I prefer the second way, making destroy async feels scary.

@zcbenz

zcbenz May 1, 2017

Contributor

I prefer the second way, making destroy async feels scary.

@zcbenz

zcbenz approved these changes May 1, 2017

This change looks good to me.

The destruction of WebContents is getting too complicated since we have too many ways to destroy a WebContents under different cases, we should find a way to simplify it in future.

@zcbenz zcbenz merged commit 9e0c308 into master May 1, 2017

9 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
electron-linux-arm Build #6435541 succeeded in 78s
Details
electron-linux-ia32 Build #6435542 succeeded in 73s
Details
electron-linux-x64 Build #6435543 succeeded in 162s
Details
electron-mas-x64 Build #4050 succeeded in 7 min 23 sec
Details
electron-osx-x64 Build #4052 succeeded in 8 min 24 sec
Details
electron-win-ia32 Build #3036 succeeded in 9 min 32 sec
Details
electron-win-x64 Build #3010 succeeded in 9 min 43 sec
Details

@zcbenz zcbenz deleted the window_close_patch branch May 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment