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: store portal restore token under the right source ID #40098
Conversation
Hi, can you please target this to WebRTC upstream? I see you also have another related fixes, it's unfortunate these will land only for Electron and not for all the others. I will test this myself, it will take a while for me to build Chromium as I haven't updated my checkout for a while, but I'm not sure it will fix the issue I'm seeing with Google Meet. I'm also not sure it's correct, usually the |
It doesn't fix my issue with Google Meet, but I think I understand the issue you are trying to fix. I believe the main problem in your case is that once the stream is stopped, it will bump the For Google Meet I can see it properly stores the token with |
@grulja I would prefer to target upstream, but WebRTC's CLA requirement is a significant hurdle for me. My employer does not permit CLAs and I'll have to check if there's an exception process. Did you check the D-Bus calls that were being made? It was helpful for me to debug this issue. I observed that Electron was not passing the restore token in |
@grulja I looked further into the Google Meet issue. It appears that after the source is chosen, two desktop capturer instances are created in quick succession. The first instance takes the restore token, but is destroyed before it can replace it. When the second one tries to look for the token, it gets nothing. Here are some logs that I added to describe the issue:
The first two BaseCapturerPipeWire instances are from the Chromium picker. The restore token is stored correctly, but is taken by a transient third instance of BaseCapturerPipeWire, which lasts just a few milliseconds. The fix has to somehow avoid creating this transient instance. Delaying the destruction of BaseCapturerPipeWire is not a fix, as it'll just create a race between the portal sending a restore token and the BaseCapturerPipeWire trying to read it. This PR does fix a valid issue in Electron, but there's probably another issue that has to be fixed to avoid the duplicate permission dialogs. |
Interesting. I can certainly see in that scenario why it breaks. I wonder whether we can do a simple fix to both of our issues by just making |
I opened a bug and added you to CC: https://bugs.chromium.org/p/webrtc/issues/detail?id=15544 It should fix both issues. |
I think simply changing
This design choice is inherently racy, as the process to use and replenish a token is not an atomic operation. This is especially true for web browsers, where a stream could be restored multiple times in different threads due to website code. XDG Desktop Portal should document that the restore token will be retained if the stream is restored. It might be okay to rely on the implementation detail for now and not delete tokens, but only for race conditions. The returned restore token should be stored under the right source ID to handle other cases mentioned in the documentation. |
XDG Desktop Portal provides restore tokens to restore a previously selected PipeWire stream instead of prompting the user again. This restore token is single use only and it has to be replaced when the stream is completed/stopped. BaseCapturerPipewire maintains two source IDs: one is initialized by the constructor for new sources (source_id_) and another is for capturing previously selected sources (selected_source_id_). The restore token was always being stored under `source_id_`, even if the capture was ongoing for `selected_source_id_`. This prevents a stream from being restored more than once. Fix that by storing the restore token under the selected source ID if it exists.
7636f22
to
a26eadd
Compare
Replaced with the upstream patch, which subsumes my previous patch and includes an additional fix for race conditions. |
Release Notes Persisted
|
I have automatically backported this PR to "26-x-y", please check out #40191 |
I have automatically backported this PR to "28-x-y", please check out #40192 |
I have automatically backported this PR to "27-x-y", please check out #40193 |
…0098) XDG Desktop Portal provides restore tokens to restore a previously selected PipeWire stream instead of prompting the user again. This restore token is single use only and it has to be replaced when the stream is completed/stopped. BaseCapturerPipewire maintains two source IDs: one is initialized by the constructor for new sources (source_id_) and another is for capturing previously selected sources (selected_source_id_). The restore token was always being stored under `source_id_`, even if the capture was ongoing for `selected_source_id_`. This prevents a stream from being restored more than once. Fix that by storing the restore token under the selected source ID if it exists.
Description of Change
XDG Desktop Portal provides restore tokens to restore a previously selected PipeWire stream instead of prompting the user again. This restore token is single use only and it has to be replaced when the stream is completed/stopped.
BaseCapturerPipewire maintains two source IDs: one is initialized by the constructor for new sources (
source_id_
) and another is for capturing previously selected sources (selected_source_id_
). The restore token was always being stored undersource_id_
, even if the capture was ongoing forselected_source_id_
. This prevents a stream from being restored more than once. Fix that by storing the restore token under the selected source ID if it exists.Fixes #40097
cc @VerteDinde (this might fix some of the duplicate permission dialog issues)
Checklist
npm test
passesRelease Notes
Notes: Fixed some redundant permission dialogs while screen sharing on Wayland.