hyprland-community / pyprland

Scratchpads & many goodies for Hyprland [maintainer=@fdev31]
MIT License
345 stars 15 forks source link

[BUG] OSError: AF_UNIX path too long #102

Closed explosion-mental closed 2 months ago

explosion-mental commented 4 months ago

Pyprland version 2.2.20

Describe the bug Running pypr causes an error, being unable to run the daemon as usual. I tried both pyprland and pyprland-git from AUR.

To Reproduce Steps to reproduce the behavior:

  1. Run pypr

Expected behavior pypr command to work normally.

Additional context

Unhandled exception:
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/pyprland/command.py", line 509, in main
    asyncio.run(run_daemon() if invoke_daemon else run_client())
  File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/command.py", line 349, in run_daemon
    manager.server = await asyncio.start_unix_server(manager.read_command, CONTROL)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/streams.py", line 113, in start_unix_server
    return await loop.create_unix_server(factory, path, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/unix_events.py", line 319, in create_unix_server
    sock.bind(path)
OSError: AF_UNIX path too long
fdev31 commented 4 months ago

Can you "echo $XDG_RUNTIME_DIR" in a terminal ?

explosion-mental commented 3 months ago
$ echo $XDG_RUNTIME_DIR
/home/explo/.local/runtime
fdev31 commented 3 months ago

Can you edit the file "/usr/lib/python3.12/asyncio/streams.py", line 113, in start_unix_server, adding a print("path") as follows:

    print("PATH:", path)
    return await loop.create_unix_server(factory, path, **kwds)

And then reply with the path which has been printed ?

explosion-mental commented 3 months ago

damn

PATH: /home/explo/.local/runtime/hypr/cba1ade848feac44b2eda677503900639581c3f4_1716045925_1423382486/.pyprland.sock
Unhandled exception:
...

should I restore to default XDG_RUNTIME_DIR ?

fdev31 commented 3 months ago

It looks like a pretty low limitation on your system... 109 characters aren't that much... After some research it looks like the limit for unix paths is very short, so it's not specific to your system and I can imagine this can happen to more people. I'll try to mitigate it.

fdev31 commented 3 months ago

I can try to shave a few characters but I'm surprised you didn't get issues with other tools communicating with hyprland... maybe it's a matter of one character or two... sorry to ask you another test:

In pyprland/command.py, if you replace

CONTROL = f"{IPC_FOLDER}/.pyprland.sock"

with

CONTROL = f"{IPC_FOLDER}/.pypr.sock"

is that still failing somewhere else ? (you'll need to restart pypr completely to apply the new socket path on the daemon too)

fdev31 commented 3 months ago

I can think about a better improvement, but it will take more time which I don't have today, but now the problem is clear at least and there are some solutions I can think of.

fdev31 commented 3 months ago

Pushed something really quick & dirty, probably not the final fix, hope it helps! (you'll need to use the -git package)

fdev31 commented 3 months ago

I finally procrastinated & didn't do what was supposed to keep me busy... can you confirm the latest git version fixes your problem ?

explosion-mental commented 3 months ago

I finally procrastinated & didn't do what was supposed to keep me busy... can you confirm the latest git version fixes your problem ?

I understand this feeling 😿

Is something deprecated? I get that toggle isn't found, 2 times after that it disconnects from the coekts:

Failed to open control socket, is pypr daemon running ?
Command failed.

The path problems seems to be solved tho.

fdev31 commented 3 months ago

Nope, toggle should work... Is it also happening with the first version of the fix?

EDIT: rather check the pypr daemon logs while launching commands in a terminal... I don't think it's related to this change

explosion-mental commented 3 months ago

Not sure what happen, but everything works now (probably some issue with owning the socket). Thanks :]

fdev31 commented 3 months ago

Do you have a chance to run:

python -c "import os; print(os.pathconf('/', 'PC_PATH_MAX'))" 
python -c "import os; print(os.pathconf('/tmp', 'PC_PATH_MAX'))" 

... and tell what are the printed values ?

fdev31 commented 3 months ago

Or just use the latest git version and tell me if it breaks...

explosion-mental commented 3 months ago

size

The problem seems to come up again tho, I just updated to lastest hyprland-no-systemd-git and -pyprland-git` pkges.

pyprland version: 2.3.5-13

fdev31 commented 3 months ago

Really ?! I'm so disappointed... Can you try tweaking MAX_SOCKET_PATH_LEN = 108 in the common.py file, is 107 making it work ? or a lower value ?

fdev31 commented 3 months ago

Just in case it was my mistake introducing a difference of 1 AND you are exactly on the limit, you can also try the latest git version...

explosion-mental commented 2 months ago

I just leave XDG_RUNTIME_DIR alone again. Even Hyprland event socket was throwing out errors (failed to set up), which is the reason why sometimes I got "command not found: toggle", since it couldn't event comunicate with hyprland (I suppose..).

$ echo $XDG_RUNTIME_DIR
/run/user/1000
explosion-mental commented 2 months ago

I can only think runtime dir that I have assign to require some special treatment, like being a tmpfs or the like. I'm not really sure. But finishing the last comment, restoring (or not defining the env var to anything else) XDG_RUNTIME_DIR seems to work out.