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

Anaconda server crash due to Jedi version #944

Open
RaytingSec opened this issue Oct 19, 2024 · 1 comment
Open

Anaconda server crash due to Jedi version #944

RaytingSec opened this issue Oct 19, 2024 · 1 comment

Comments

@RaytingSec
Copy link

RaytingSec commented Oct 19, 2024

Expected Behaviour

Open a python file with ST, Anaconda provides it's features such as docs, autocomplete, and linting

Actual Behaviour

ConnectionRefusedError is thrown

Steps to Reproduce

  • Fresh install of Fedora 40, install sublime-text

  • Set syntax to Python

  • Write a python script that makes use of other libraries such as:

    import datetime
    
    dt = datetime.now()
  • While writing the last line, the autocomplete should throw an error

ST3, Anaconda and OS versions

  • Sublime Text 4180
  • Anaconda 2.3.0
  • Fedora 40
  • Python 3.12.6 (system version)

ST3 Console Logs

See Troubleshooting section

Anaconda's JsonServer Logs

Note: Anaconda's JsonServer logs can be found in:

  • Linux: ~/.local/share/anaconda/logs
  • OS X: ~/Library/Logs/anaconda
  • Windows: %APPDATA\Anaconda\Logs

See Troubleshooting section

Troubleshooting

TLDR, it seems the Jedi version need to be bumped.

For a while now, Anaconda's server is unable to start up and I get this as part of the error in ST console:

ConnectionRefusedError: [Errno 111] Connection refused

I'm unable to find a detailed message unless I run jsonserver.py myself, then I can see more detailed message like stacktrace:

2024-10-19 02:08:32,691: ERROR   : too many values to unpack (expected 2)
2024-10-19 02:08:32,691: ERROR   : Traceback (most recent call last):
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 112, in found_terminator
    self.handle_command(
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 144, in handle_command
    ).run()
      ^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 28, in run
    super(JediHandler, self).run()
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/lib/anaconda_handler.py", line 49, in run
    command(**kwargs)
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 123, in doc
    Doc(
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/doc.py", line 34, in __init__
    super(Doc, self).__init__(callback, uid)
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/base.py", line 14, in __init__
    self.run()
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/doc.py", line 58, in run
    else self._html(definition)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/commands/doc.py", line 84, in _html
    html.unescape(definition.docstring()), quote=False
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/classes.py", line 301, in docstring
    doc = self._get_docstring()
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/classes.py", line 312, in _get_docstring
    return self._name.py__doc__()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/names.py", line 236, in py__doc__
    names = convert_names([self], prefer_stub_to_compiled=False)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/gradual/conversion.py", line 154, in convert_names
    return _try_stub_to_python_names(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/utils.py", line 16, in wrapper
    return list(func(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/gradual/conversion.py", line 83, in _try_stub_to_python_names
    converted_names = converted.goto(name.get_public_name())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/base_value.py", line 493, in goto
    return reduce(add, [c.goto(*args, **kwargs) for c in self._set], [])
                        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/base_value.py", line 72, in goto
    names = finder.filter_name(filters, name_or_str)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/finder.py", line 36, in filter_name
    names = filter.get(string_name)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/compiled/value.py", line 435, in get
    return self._get(
           ^^^^^^^^^^
  File "/home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/compiled/value.py", line 454, in _get
    has_attribute, is_descriptor = allowed_getattr_callback(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

After much digging and troubleshooting, I found when I install Jedi via pip, it's the latest version jedi-0.19.1 and some of the code such as allowed_getattr_callback() involved in the too many values to unpack has changed. It returns three instead of two.

I attempted a crude patch by rsync from .venv/lib/python3.12/site-packages/jedi/ to ~/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/, and Anaconda appears to be working fine now. I have linting and autocomplete again, and I no longer see errors in my ~/.local/share/anaconda/ logs.

Edit: I can open a PR, or try checking for other library updates. But how can I test the changes, or who is able to test it? Long time user and happy to contribute a bit to a tool I love.

@RaytingSec
Copy link
Author

There's a second problem involving virtual environments, where the JSON server doesn't start and results in the connection refused error:

anacondaST3: ERROR - Anaconda worker could not start because:

can not connect to /home/rayting/.local/share/anaconda/run/anacondatest/anaconda.sock. tried to connect 21 times during 2.0 seconds

check that there is Python process executing the anaconda jsonserver.py script running in your system. If there is, check that the Unix Domain Socket file /home/rayting/.local/share/anaconda/run/anacondatest/anaconda.sock exists and that you can connect to it writing the following script in your Sublime Text 3 console:

import socket; socket.socket(socket.AF_UNIX, socket.SOCK_STREAM).connect(/home/rayting/.local/share/anaconda/run/anacondatest/anaconda.sock)

If anaconda works just fine after you received this error and the command above worked you can make anaconda to do not show you this error anymore setting the 'swallow_startup_errors' to 'true' in your configuration file.

Steps to reproduce

  • Create a new folder and virtualenv, such as:

    mkdir anacondatest && cd anacondatest
    virtualenv .venv && source .venv/bin/activate
    subl -n ./
  • Save it as a new project in ST

  • Edit the project to use the virtualenv python, for example, this is what I have:

    {
        "folders":
        [
            {
                "follow_symlinks": true,
                "path": "/home/rayting/code/anacondatest",
            }
        ],
        "build_systems":
        [
            {
                "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
                "name": "Anaconda Python Builder",
                "selector": "source.python",
                "shell_cmd": "\"/home/rayting/code/anacondatest/.venv/bin/python\" -u \"$file\"",
            }
        ],
        "settings":
        {
            "python_interpreter": "/home/rayting/code/anacondatest/.venv/bin/python"
        }
    }
  • Create a python file and follow the original reproduction steps with import datetime and such

  • A new python process running jsonserver.py will not spawn, for example this is my ps aux | grep [s]ubl output:

    rayting    57602  4.1  0.4 762380 136112 ?       Sl   04:27   0:03 /opt/sublime_text/sublime_text --detached
    rayting    57612  0.0  0.0  86700  2488 ?        Sl   04:27   0:00 /opt/sublime_text/crash_handler --no-rate-limit --database=/home/rayting/.cache/sublime-text/Crash Reports --metrics-dir=/home/rayting/.cache/sublime-text/Crash Reports --url=https://crash-server.sublimehq.com/api/upload --annotation=hash=164943210266
    rayting    57638  0.6  0.0 559572 27720 ?        Sl   04:27   0:00 /opt/sublime_text/plugin_host-3.3 57602 /opt/sublime_text/sublime_text 18:57612 /home/rayting/.config/sublime-text /home/rayting/.cache/sublime-text /opt/sublime_text/Packages
    rayting    57641  1.7  0.1 663920 62600 ?        Sl   04:27   0:01 /opt/sublime_text/plugin_host-3.8 57602 /opt/sublime_text/sublime_text 18:57612 /home/rayting/.config/sublime-text /home/rayting/.cache/sublime-text /opt/sublime_text/Packages
    
  • I found it's because pyasynchat needs to be installed manually in the virtualenv, then the relevant processes will start:

    rayting   127078  3.9  0.5 852020 188232 ?       Sl   04:47   0:02 /opt/sublime_text/sublime_text --detached
    rayting   127151  0.0  0.0  86700  2492 ?        Sl   04:47   0:00 /opt/sublime_text/crash_handler --no-rate-limit --database=/home/rayting/.cache/sublime-text/Crash Reports --metrics-dir=/home/rayting/.cache/sublime-text/Crash Reports --url=https://crash-server.sublimehq.com/api/upload --annotation=hash=164943210266
    rayting   127199  0.5  0.0 559600 27436 ?        Sl   04:47   0:00 /opt/sublime_text/plugin_host-3.3 127078 /opt/sublime_text/sublime_text 18:127151 /home/rayting/.config/sublime-text /home/rayting/.cache/sublime-text /opt/sublime_text/Packages
    rayting   127202  2.0  0.1 663892 62256 ?        Sl   04:47   0:01 /opt/sublime_text/plugin_host-3.8 127078 /opt/sublime_text/sublime_text 18:127151 /home/rayting/.config/sublime-text /home/rayting/.cache/sublime-text /opt/sublime_text/Packages
    rayting   127864  1.4  0.2 445752 67952 ?        Sl   04:47   0:00 /home/rayting/code/anacondatest/.venv/bin/python -B /home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py -p anacondatest -e /home/rayting/code/anacondatest 127202
    rayting   129386  0.5  0.0 256868 26780 ?        S    04:47   0:00 /home/rayting/code/anacondatest/.venv/bin/python /home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/compiled/subprocess/__main__.py /home/rayting/.config/sublime-text/Packages/Anaconda/anaconda_lib 3.12.6
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant