emersion / xdg-desktop-portal-wlr

xdg-desktop-portal backend for wlroots
MIT License
579 stars 53 forks source link

Handle pipewire restarts #276

Closed cillian64 closed 11 months ago

cillian64 commented 11 months ago

If the pipewire daemon restarted while xdpw was running then our pipewire connection would drop and attempting to start a screencast wouldn't work until user manually restarted xdpw.

This commit adds a listener for fatal core connection errors from pipewire. In the handler it cleans up the connection and marks it as dead. Then, when the user attempts to start a screencast, we reconnect the pipewire core if needed.

To reproduce the problem:

With this change applied, the screen capture works after restarting pipewire (after testing the bad case, make sure to restart Firefox before testing with the fix applied).

Fixes #242, fixes #178

emersion commented 11 months ago

Can't we just exit when we loose the connection to PipeWire?

cillian64 commented 11 months ago

I've just tested and that does work, assuming you're running xdpw from systemd or similar. I guess it's a little simpler than restarting the pipewire connection.

Would you like me to update this PR to do that? If so, do you think this is an abort() or exit(-1) situation?

cillian64 commented 11 months ago

Actually, I just remembered one issue I had in testing was that if you try to reconnect to pipewire too soon after the error listener fires it's possible to reconnect to the old pipewire daemon before it has stopped (it seems like the server disconnects all the clients before it stops listening for new connections). I'd hope that this would just fire the error listener again but I'm not sure. In practice xdpw being restarted by systemd seems to take long enough to avoid this problem but it's potentially racey.

emersion commented 11 months ago

Yeah, I'd prefer to exit(1) when we get disconnected from PipeWire or Wayland. Trying to recreate our state doesn't seem worth the trouble.