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: crash using powerMonitor before ready event #40888

Merged
merged 2 commits into from Jan 9, 2024

Conversation

codebytere
Copy link
Member

Description of Change

Closes #40694.
Refs #37937.

This PR fixes a crash resultant in trying to listen to power-related events before the ready event is emitted on Linux. This was happening because the PowerObserverLinux ctor called bluez::BluezDBusThreadManager::Get(), which assumed that bluez::BluezDBusThreadManager::Initialize() had already been called and CHECKed if it hadn't been. However, our existing logic did not call bluez::BluezDBusThreadManager::Initialize() until ElectronBrowserMainParts::PostCreateMainMessageLoop(), which meant that trying to use:

  powerMonitor.on('suspend', () => {
    console.log('suspend')
  });

  powerMonitor.on('resume', () => {
    console.log('resume')
  });

before the ready event would immediately die. I chose to fix this by calling bluez::BluezDBusThreadManager::Initialize() as soon as it was needed, and adding a check to ensure that it was not initialized more than once. Alternately, we can bring back the ready event requirement.

Checklist

Release Notes

Notes: Fixed a crash resultant from trying to listen to power-related events before the ready event was emitted on Linux.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/26-x-y PR should also be added to the "26-x-y" branch. target/27-x-y PR should also be added to the "27-x-y" branch. target/28-x-y PR should also be added to the "28-x-y" branch. target/29-x-y PR should also be added to the "29-x-y" branch. labels Jan 4, 2024
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 4, 2024
@codebytere codebytere changed the title fix: crash using powerMonitor before ready event fix: crash using powerMonitor before ready event Jan 4, 2024
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

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

lazy initialize seems like a good approach to me 👍🏻

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.

Minor nit: wouldn't it be better to continue using the wrapper class to avoid missing any additional bluez initialization or shutdown paths that might get added in future ?

if (!bluez::BluezDBusManager::IsInitialized())
  bluez::DBusBluezManagerWrapperLinux::Initialize();

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 5, 2024
@codebytere
Copy link
Member Author

@deepak1556 done!

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.

Thanks!

@codebytere
Copy link
Member Author

Failing test unrelated:

reporting api sends a report for an intervention

@codebytere codebytere merged commit c184b93 into main Jan 9, 2024
17 of 18 checks passed
@codebytere codebytere deleted the fix-power-monitor-ready-crash branch January 9, 2024 08:41
Copy link

release-clerk bot commented Jan 9, 2024

Release Notes Persisted

Fixed a crash resultant from trying to listen to power-related events before the ready event was emitted on Linux.

@trop
Copy link
Contributor

trop bot commented Jan 9, 2024

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

@trop trop bot added the in-flight/26-x-y label Jan 9, 2024
@trop trop bot removed the target/26-x-y PR should also be added to the "26-x-y" branch. label Jan 9, 2024
@trop
Copy link
Contributor

trop bot commented Jan 9, 2024

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

@trop
Copy link
Contributor

trop bot commented Jan 9, 2024

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

@trop
Copy link
Contributor

trop bot commented Jan 9, 2024

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

@trop trop bot added in-flight/27-x-y in-flight/28-x-y in-flight/29-x-y merged/27-x-y PR was merged to the "27-x-y" branch. merged/26-x-y PR was merged to the "26-x-y" branch. merged/29-x-y PR was merged to the "29-x-y" branch. merged/28-x-y PR was merged to the "28-x-y" branch. and removed target/27-x-y PR should also be added to the "27-x-y" branch. target/28-x-y PR should also be added to the "28-x-y" branch. target/29-x-y PR should also be added to the "29-x-y" branch. in-flight/27-x-y in-flight/26-x-y in-flight/29-x-y in-flight/28-x-y labels Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/26-x-y PR was merged to the "26-x-y" branch. merged/27-x-y PR was merged to the "27-x-y" branch. merged/28-x-y PR was merged to the "28-x-y" branch. merged/29-x-y PR was merged to the "29-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: crashed when powerMonitor listens on suspend/resume event in main process at 27.1.x
5 participants