Xpra-org / xpra

Persistent remote applications for X11; screen sharing for X11, MacOS and MSWindows.
https://xpra.org/
GNU General Public License v2.0
1.95k stars 169 forks source link

Attach fails on Wayland with "NameError: name 'xsync' is not defined" #4377

Open jchv opened 1 week ago

jchv commented 1 week ago

Describe the bug Running xpra attach on Xpra 6.1.2 fails with the following error:

$ xpra attach ...
2024-10-08 10:46:35,268 Xpra GTK3 X11 client version 6.1.2
2024-10-08 10:46:35,271  running on Linux 6.11.1
2024-10-08 10:46:35,271  cpython 3.12
2024-10-08 10:46:35,271  window manager is 'sway on wayland'
2024-10-08 10:46:35,828 GStreamer version 1.24.3
2024-10-08 10:46:35,844 Warning: failed to load the GObject notifier
2024-10-08 10:46:35,844  Namespace Notify not available
2024-10-08 10:46:35,848 created unix domain sockets:
2024-10-08 10:46:35,848  '/run/user/1000/xpra/clients/curly-299510'
2024-10-08 10:46:36,017 removing unix domain socket '/run/user/1000/xpra/clients/curly-299510'
xpra main error:
Traceback (most recent call last):
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/scripts/main.py", line 138, in main
    return run_mode(script_file, cmdline, err, options, args, mode, defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/scripts/main.py", line 507, in run_mode
    return do_run_mode(script_file, cmdline, error_cb, options, args, full_mode, defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/scripts/main.py", line 604, in do_run_mode
    return run_client(script_file, cmdline, error_cb, options, args, mode)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/scripts/main.py", line 1484, in run_client
    app = get_client_app(cmdline, error_cb, opts, extra_args, mode)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/scripts/main.py", line 1653, in get_client_app
    app = get_client_gui_app(error_cb, opts, request_mode, extra_args, mode)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/scripts/main.py", line 1725, in get_client_gui_app
    app.init_ui(opts)
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/client/gui/ui_client_base.py", line 224, in init_ui
    self.keyboard_helper = self.keyboard_helper_class(send_keyboard, opts.keyboard_sync,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/client/gtk3/keyboard_helper.py", line 31, in __init__
    self.update()
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/client/gtk3/keyboard_helper.py", line 84, in update
    super().update()
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/client/gui/keyboard_helper.py", line 300, in update
    self.query_xkbmap()
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/client/gui/keyboard_helper.py", line 278, in query_xkbmap
    self.layout, self.layouts, self.variant, self.variants, self.options = self.get_layout_spec()
                                                                           ^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/client/gui/keyboard_helper.py", line 231, in get_layout_spec
    layout, layouts, variant, variants, options = self.keyboard.get_layout_spec()
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k442kmivv1v9i051xka9a4dk7wfcpaip-xpra-6.1.2/lib/python3.12/site-packages/xpra/platform/posix/keyboard.py", line 274, in get_layout_spec
    with xsync:
         ^^^^^
NameError: name 'xsync' is not defined

Normally I would test with the latest HEAD just to be sure, but looking at the code I don't believe it's possible that the bug has been fixed since 6.1.2 was released.

Downstream report: https://github.com/NixOS/nixpkgs/issues/347294

To Reproduce It's easy to reproduce this bug even without Wayland because the way Wayland is detected is imperfect. e.g. You should be able to trigger it by setting GDK_BACKEND="wayland" WAYLAND_DISPLAY="" or something similar.

System Information (please complete the following information):

Additional context I normally use Xpra under XWayland, which makes more sense to me anyways given what it is doing. If I use GDK_BACKEND=x11 then it works again, since the Wayland detection will then return false.

The bug here seems to come down to the fact that although xsync is conditionally imported, it is still used unconditionally in some codepaths that are hit under Wayland. I'm not sure how this should be fixed. Maybe failing all else the commit that makes the import conditional should just be reverted for now.

Thanks.

totaam commented 1 week ago

That's odd because I do test under wayland, before every release.

Something fishy is going on if you end up in this code path. The keyboard bindings should only be loaded under X11: https://github.com/Xpra-org/xpra/blob/93141108c80c87232516c667ab4f446cbbc93490/xpra/platform/posix/keyboard.py#L28-L32 This should guard against calling xsync: https://github.com/Xpra-org/xpra/blob/93141108c80c87232516c667ab4f446cbbc93490/xpra/platform/posix/keyboard.py#L273-L275 But I guess that the import is more strict: https://github.com/Xpra-org/xpra/blob/93141108c80c87232516c667ab4f446cbbc93490/xpra/platform/posix/keyboard.py#L18-L19

And it is possible to have both is_Wayland and is_X11 return True... eb3057cc40c0ef10e0bdbf3d4e3802f843936031 should fix this.

jchv commented 1 week ago

Wow, thanks for looking at this immediately. I believe this should entirely prevent the problem.


I think what's actually going on here is I'm always getting XWayland under Xpra 6, and in spite of that is_Wayland sometimes returns true anyways.

I actually want it to always load under XWayland but I'm guessing this signals another issue, probably in the NixOS package. If I try to force native Wayland, GTK still tries to load in X11 mode.

$ GDK_BACKEND=wayland DISPLAY= XPRA_NOX11=yes xpra attach ...
failed to initialize Gtk, no display?

(I did test that other Wayland apps are launching fine in the terminal.)

I can't really dig into it right now but I will try to take a look soon. I don't want to waste your time on what is possibly a downstream problem.