Repository navigation
Fix DesktopCapture crash on Mac OS X - #418
Conversation
@alexeykuzmin I can do that, but are you 100% sure? Also it seems to enable correct behavior of bluetooth devices (which is overlooked by earlier SDKs). |
|
Reverted it for now. I propose to keep it in the repo history though so that people can still build with SDK 10.13, which seems to be officially supported (at least if we choose to believe the Chromium documentation). |
|
@ilya-edrenkin, yes, I'm sure.
We cannot be 100% sure, patching Chromium code we always risk breaking something.
Thanks! |
Is it possible to write a test in Electron to reproduce the crash? |
It would be really nice to have, but the behavior is non-deterministic. https://github.com/Ajeey/electron-crash-demo provides an example app that reliably crashes eventually, but researching the exact triggering sequence of events requires diving deep into the webrtc code. |
|
While trying to pinpoint the problem further to automate testing, got a new kind of backtrace: Although it seemes be a separate issue, I thought the root cause is likely the same. However, I have found that the As far as I can see, it could only stem from failure in the constructor: Digging deeper, it seems to be the result of pthread_rwlock_init failure: Unfortunately, I couldn't find out why the However, I believe that we should just account for the fact that Thoughts/suggestions? |
|
If the system refuses to return a valid rwlock, we wait with a random backoff (to prevent contention) and then retry. Note: the backoff parameters were not tuned, for this I would likely need fuzzing on a variety of systems which I don't have; probably it's better to leave this to WebRTC maintainers. With this fix, I don't observe any more crashes on MacOS X 10.12.6 with a long-running Electron-crash-demo program from @Ajeey, even when making screenshots etc. This is not a proof that this will never happen though. I have checked the WebRTC code for other unsafe return values; I still don't understand the root cause of the problem fixed in the first commit. As far as I can see, |
|
OK, some good news: finally I was able to obtain my own coredump for the original problem. This means that the proposed nullptr-check for However, what happens next is really interesting: We see that the state of This could happen if the DisplayStreamManager indeed has function DestroyStream that calls I should probably stop guesswork and just rebuild with ASan (the main problem is that chromium builds take enormous amount of time on the only Mac machine I currently have access to, and the bug itself takes random amount of time to reproduce). |
|
So far my hypothesis is that The loop |
|
@alexeykuzmin Finally pinpointed and fixed the root causes. Please review. |
|
@ilya-edrenkin If you believe that It would be great if you could submit a patch for the WebRTC repo. Here is a contributor guide https://webrtc.org/contributing/ |
|
@alexeykuzmin I have mentioned it in a corresponding issue: https://bugs.chromium.org/p/webrtc/issues/detail?id=8646#c2
That's not entirely true. The return value of RWLockWrapper::CreateRWLock is not safe, and in an (unlikely) event of contention on system resources it might return NULL which inevitably leads to crash on dereference. It makes sense to provide a defense from this. However, what causes most of the observed crashes is just concurrency bugs. |
Thank you!
But they can give much better advice about how it should be done properly. |
|
Basically, the WebRTC developers blame the fact that NativeDesktopMediaList is heavily modified in Electron (https://bugs.chromium.org/p/webrtc/issues/detail?id=8646#c5):
@zcbenz When you have time, could you please pay some attention to this feedback from WebRTC developers? It would be really great to know your opinion on that. I can understand why it leads to race condition between the However, I currently cannot see how this could explain the crash #418 (comment). Here we quite clearly observe a broken std::map The only two functions that modify this |
|
@ilya-edrenkin Thanks a ton for looking into this crash bug. This specific issue is turning out to be a show stopper for us in terms of picking electron vs node-webkit. I hope this PR gets pulled into electron soon :) |
|
@ilya-edrenkin Thanks for looking into this, I'll see if it is possible to avoid the race condition on Electron's side according to webrtc developers' description. If not I think we should probably add this patch. |
|
@zcbenz Thanks for the feedback! Re the patch:
Even if we fix this problem on Mac, aren't there problems on other platforms hiding out there? If there exist other DesktopCapturer crashes on Electron, that could have something to do with it.
|
|
I have looked into the implementation in upstream Chromium, and the I think Chromium does not (or rarely) have this problem because they are using So having this patch merged seems to be the best solution to the crash. |
|
I'm rebasing this branch on master |
|
@zcbenz Any approx timeline on when this will be pulled into electron? |
|
It will be in next major/minor release, we don't have an estimate date yet. |
|
@zcbenz In which version of electron is this fix landed? Could not find this fix on the release page. |
|
@Ajeey I think it is in 2.0, we probably forgot to add this item in changelog. |
|
Thank you 👍 |
Fixes crash described in electron/electron#9600, electron/electron#11304.
The root cause of the observed crashes was a concurrency bug. Another possible cause for this kind of behavior could be a NULL pointer returned from a RWLock factory.