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

refactor: rewire the desktop capturer API to remove race conditions #18029

Merged
merged 1 commit into from
Apr 29, 2019

Conversation

MarshallOfSound
Copy link
Member

We now create a new instance of atom::api::DesktopCapturer for every request instead of weirdly re-using the same instance and queuing requests. This means there is now a 1:1 relationship between request and DesktopCapturer so there isn't a race condition between the observer for one request calling back before the observer of another. This is an issue ever since the backing APIs moved to worker threads.

This also does a few things to ensure memory management

  • Only ever listen to one event per-request, after that we wipe the emit function to ignore all future events
  • Ensures we clean up the window_capturer_, screen_capturer_ and captured_sources_ in native land once the request is over.

This in theory fixes a flake we've been seeing on CI where we try to resolve the promise for a request that no longr exists.

Notes: Fixed race condition in the desktopCapturer module where some requests for sources would never be resolved or unhandled exceptions would be thrown in the main process.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 29, 2019
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.

the js stuff seems janky as heck to me but i don't have any better suggestions so /shrug

requesting changes for minor nits in the c++

atom/browser/api/atom_api_desktop_capturer.cc Outdated Show resolved Hide resolved
atom/browser/api/atom_api_desktop_capturer.cc Outdated Show resolved Hide resolved
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.

Agree with the changes proposed by @nornagon , LGTM otherwise.

We now create a new instance of atom::api::DesktopCapturer for every
request instead of weirdly re-using the same instance and queuing
requests.  This means there is now a 1:1 relationship between request
and DesktopCapturer so there isn't a race condition between the observer
for one request calling back before the observer of another.  This is an
issue ever since the backing APIs moved to worker threads.

This also does a few things to ensure memory management
* Only ever listen to one event per-request, after that we wipe the emit
function to ignore all future events
* Ensures we clean up the window_capturer_, screen_capturer_ and
captured_sources_ in native land once the request is over.

This _in theory_ fixes a flake we've been seeing on CI where we try to
resolve the promise for a request that no longerr exists.
@MarshallOfSound
Copy link
Member Author

@nornagon Yeah the JS side of this is Not Too Great ™️ but this was the shortest refactor that fixed the issues. I'm planning on following up at some point with a proper rewrite with promises in native land and such 🤔 But that's a bigger task

@release-clerk
Copy link

release-clerk bot commented Apr 29, 2019

Release Notes Persisted

Fixed race condition in the desktopCapturer module where some requests for sources would never be resolved or unhandled exceptions would be thrown in the main process.

@MarshallOfSound MarshallOfSound deleted the refactor-desktop-capturer branch April 29, 2019 20:21
@trop
Copy link
Contributor

trop bot commented Apr 29, 2019

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

@trop
Copy link
Contributor

trop bot commented Apr 29, 2019

I have automatically backported this PR to "6-0-x", please check out #18042

@trop trop bot added the merged/6-0-x label Apr 30, 2019
kiku-jw pushed a commit to kiku-jw/electron that referenced this pull request May 16, 2019
…lectron#18029)

We now create a new instance of atom::api::DesktopCapturer for every
request instead of weirdly re-using the same instance and queuing
requests.  This means there is now a 1:1 relationship between request
and DesktopCapturer so there isn't a race condition between the observer
for one request calling back before the observer of another.  This is an
issue ever since the backing APIs moved to worker threads.

This also does a few things to ensure memory management
* Only ever listen to one event per-request, after that we wipe the emit
function to ignore all future events
* Ensures we clean up the window_capturer_, screen_capturer_ and
captured_sources_ in native land once the request is over.

This _in theory_ fixes a flake we've been seeing on CI where we try to
resolve the promise for a request that no longerr exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-pr 🌱 PR opened in the last 24 hours
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants