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

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

Open
jchv opened this issue Oct 8, 2024 · 2 comments
Open

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

jchv opened this issue Oct 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jchv
Copy link

jchv commented Oct 8, 2024

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: NixOS/nixpkgs#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):

  • Server OS: NixOS 24.05
  • Client OS: NixOS unstable
  • Xpra Server Version 5.0.9
  • Xpra Client Version 6.1.2

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.

@jchv jchv added the bug Something isn't working label Oct 8, 2024
totaam added a commit that referenced this issue Oct 8, 2024
@totaam
Copy link
Collaborator

totaam commented Oct 8, 2024

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:

if is_X11():
try:
# pylint: disable=import-outside-toplevel
from xpra.x11.bindings.keyboard import X11KeyboardBindings
self.keyboard_bindings = X11KeyboardBindings()

This should guard against calling xsync:
if self.keyboard_bindings:
with xsync:
props = self.keyboard_bindings.getXkbProperties()

But I guess that the import is more strict:
if is_X11() and not is_Wayland():
from xpra.gtk.error import xsync

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

@jchv
Copy link
Author

jchv commented Oct 8, 2024

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.

totaam added a commit that referenced this issue Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants