Skip to content
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

fix: do not destroy thread in UI thread #23495

Merged
merged 1 commit into from
May 12, 2020
Merged

Conversation

zcbenz
Copy link
Member

@zcbenz zcbenz commented May 11, 2020

Description of Change

Destroying a thread implies joining it, and it should not be done in UI thread, otherwise it would cause assertions when DCHECK is enabled:

Backtrace:
        base::debug::CollectStackTrace [0x00007FF7C18D2172+18] (o:\base\debug\stack_trace_win.cc:284)
        base::debug::StackTrace::StackTrace [0x00007FF7C182A872+18] (o:\base\debug\stack_trace.cc:203)
        logging::LogMessage::~LogMessage [0x00007FF7C183DFF7+215] (o:\base\logging.cc:605)
        logging::LogMessage::~LogMessage [0x00007FF7C183ED40+16] (o:\base\logging.cc:598)
        base::internal::AssertBaseSyncPrimitivesAllowed [0x00007FF7C18A3DB6+214] (o:\base\threading\thread_restrictions.cc:165)
        base::internal::ScopedBlockingCallWithBaseSyncPrimitives::ScopedBlockingCallWithBaseSyncPrimitives [0x00007FF7C189F1FE+158] (o:\base\threading\scoped_blocking_call.cc:67)
        base::PlatformThread::Join [0x00007FF7C18E39DA+314] (o:\base\threading\platform_thread_win.cc:313)
        base::Thread::Stop [0x00007FF7C18A1190+128] (o:\base\threading\thread.cc:252)
        base::Thread::~Thread [0x00007FF7C18A10A7+23] (o:\base\threading\thread.cc:129)
        base::Thread::~Thread [0x00007FF7C18A2210+16] (o:\base\threading\thread.cc:127)
        base::TaskAnnotator::RunTask [0x00007FF7C188520F+431] (o:\base\task\common\task_annotator.cc:142)

The dialog module on Windows uses this behavior and crashes when used with DCHECK enabled.

This PR refactors the code to use ThreadPool to manage the threads to avoid allocating and destroying threads in UI thread, which follows the pattern used by BaseShellDialogImpl in Chromium. (We can not use BaseShellDialogImpl directly because it implies modal dialog with a parent.)

Checklist

Release Notes

Notes: none

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 11, 2020
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

shell/browser/ui/file_dialog_win.cc Outdated Show resolved Hide resolved
shell/browser/ui/file_dialog_win.cc Outdated Show resolved Hide resolved
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 12, 2020
@zcbenz zcbenz force-pushed the fix-thread-destroy branch 2 times, most recently from 57242da to ba3a3f4 Compare May 12, 2020 11:29
@deepak1556 deepak1556 merged commit 16b41dc into master May 12, 2020
@release-clerk
Copy link

release-clerk bot commented May 12, 2020

No Release Notes

@deepak1556 deepak1556 deleted the fix-thread-destroy branch May 12, 2020 17:38
@trop
Copy link
Contributor

trop bot commented May 12, 2020

I was unable to backport this PR to "8-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/8-x-y label May 12, 2020
@trop
Copy link
Contributor

trop bot commented May 12, 2020

I was unable to backport this PR to "7-2-x" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented May 12, 2020

I have automatically backported this PR to "9-x-y", please check out #23535

@trop
Copy link
Contributor

trop bot commented May 13, 2020

@zcbenz has manually backported this PR to "8-x-y", please check out #23550

@trop
Copy link
Contributor

trop bot commented May 13, 2020

@zcbenz has manually backported this PR to "7-2-x", please check out #23551

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants