jupyter-lsp / jupyterlab-lsp

Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol
https://jupyterlab-lsp.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.81k stars 149 forks source link

Ill communication in jupyter-lsp or python-lsp server: OSError-exception #806

Open TomLXXVI opened 2 years ago

TomLXXVI commented 2 years ago

Description

Recently I have created a new virtual environment with Anaconda on a Windows 11 PC, in which I installed Jupyterlab 3.4.3 together with jupyterlab-lsp and python-lsp-server. While jupyterlab is running, an error appears in the log all of the time and autocompletion etc. stops working in jupyterlab. I copied the relevant excerpt from the log below, which shows the exception that is thrown:

[E 2022-06-14 14:49:47.157 ServerApp] <LspStdIoWriter(parent=<LanguageServerSession(language_server=pylsp, argv=[‘C:\Users\Tom\anaconda3\envs\engineering-22-06\python.exe’, ‘-m’, ‘pylsp’])>)> couldn’t write message: Content-Length: 266

{"jsonrpc":"2.0","id":267,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///c:/Users/Tom/PycharmProjects/GeneralEngineering/.virtual_documents/control_systems/notebooks/mechanical_network.ipynb"},"position":{"line":2,"character":9}}} Traceback (most recent call last): File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write await convert_yielded(self._write_one(response.encode("utf-8"))) File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\asyncio\futures.py", line 284, in await yield self # This tells Task to wait for completion. File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\asyncio\tasks.py", line 304, in __wakeup future.result() File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\asyncio\futures.py", line 201, in result raise self._exception File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one self.stream.write(message) OSError: [Errno 22] Invalid argument

Reproduce

I haven't found yet how to reproduce the error. As you can see in the log excerpt above, the error happens in ServerApp (so I think it has to do with jupyter-lsp) while Jupyterlab is running in the browser (server runs on localhost). As the error happened mostly when I saw in the log message that method textDocument/documentHighlight was called, I first tought that disabling "Code Highlights" in Jupyterlab Settings could help to stabilize the connection with the language server. However, it turned out that this is not the case. I think it is because the method textDocument/documentHighlight is called frequently, changes are high that the error occurs while this method is called.

I found that when I click the refresh button of the browser, the lsp-connection gets up and running again, but after a short while the error comes up again.

Expected behavior

A stable connection with the language server (without the need to click the browser's refresh button all the time).

Context

Required: installed server extensions
Config dir: C:\Users\Tom\.jupyter

Config dir: C:\Users\Tom\anaconda3\envs\engineering-22-06\etc\jupyter
    jupyter_lsp enabled
    - Validating jupyter_lsp...
      jupyter_lsp 1.5.1 ok
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.4.3 ok
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  ok
    notebook_shim enabled
    - Validating notebook_shim...
      notebook_shim  ok

Config dir: C:\ProgramData\jupyter
Required: installed lab extensions
JupyterLab v3.4.3
C:\Users\Tom\anaconda3\envs\engineering-22-06\share\jupyter\labextensions
        jupyter-matplotlib v0.11.1 enabled ok
        jupyterlab_pygments v0.2.2 enabled ok (python, jupyterlab_pygments)
        @jupyter-widgets/jupyterlab-manager v3.1.0 enabled ok (python, jupyterlab_widgets)
        @krassowski/jupyterlab-lsp v3.10.1 enabled ok (python, jupyterlab-lsp)
Troubleshoot Output
$PATH:
        C:\Users\Tom\anaconda3\envs\engineering-22-06
        C:\Users\Tom\anaconda3\envs\engineering-22-06\Library\mingw-w64\bin
        C:\Users\Tom\anaconda3\envs\engineering-22-06\Library\usr\bin
        C:\Users\Tom\anaconda3\envs\engineering-22-06\Library\bin
        C:\Users\Tom\anaconda3\envs\engineering-22-06\Scripts
        C:\Users\Tom\anaconda3\envs\engineering-22-06\bin
        C:\Users\Tom\anaconda3\condabin
        C:\Program Files (x86)\Common Files\Oracle\Java\javapath
        C:\Program Files\AdoptOpenJDK\jre-11.0.10.9-hotspot\bin
        C:\windows\system32
        C:\windows
        C:\windows\System32\Wbem
        C:\windows\System32\WindowsPowerShell\v1.0
        C:\windows\System32\OpenSSH
        C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
        C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
        C:\Program Files\Python39\Scripts
        C:\Users\Tom\AppData\Roaming\Python\Python39\Scripts
        C:\Program Files\Python39
        C:\Program Files\Git\cmd
        C:\Windows\SysWOW64
        C:\Program Files\PuTTY
        C:\WINDOWS\system32
        C:\WINDOWS
        C:\WINDOWS\System32\Wbem
        C:\WINDOWS\System32\WindowsPowerShell\v1.0
        C:\WINDOWS\System32\OpenSSH
        C:\Program Files\Pandoc
        C:\Users\Tom\AppData\Local\Programs\Python\Python310\Scripts
        C:\Users\Tom\AppData\Local\Programs\Python\Python310
        C:\Users\Tom\AppData\Local\Microsoft\WindowsApps
        C:\Users\Tom\AppData\Local\GitHubDesktop\bin
        C:\Users\Tom\AppData\Local\Programs\MiKTeX\miktex\bin\x64
        .

sys.path:
        C:\Users\Tom\anaconda3\envs\engineering-22-06\Scripts
        C:\Users\Tom\anaconda3\envs\engineering-22-06\python310.zip
        C:\Users\Tom\anaconda3\envs\engineering-22-06\DLLs
        C:\Users\Tom\anaconda3\envs\engineering-22-06\lib
        C:\Users\Tom\anaconda3\envs\engineering-22-06
        C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages
        C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\win32
        C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\win32\lib
        C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\Pythonwin

sys.executable:
        C:\Users\Tom\anaconda3\envs\engineering-22-06\python.exe

sys.version:
        3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:34:17) [MSC v.1929 64 bit (AMD64)]

platform.platform():
        Windows-10-10.0.22000-SP0

where jupyter:
        C:\Users\Tom\anaconda3\envs\engineering-22-06\Scripts\jupyter.exe
        C:\Users\Tom\AppData\Roaming\Python\Python39\Scripts\jupyter.exe

pip list:
        Package                       Version
        ----------------------------- -----------
        anyio                         3.6.1
        argon2-cffi                   21.3.0
        argon2-cffi-bindings          21.2.0
        astroid                       2.11.5
        asttokens                     2.0.5
        attrs                         21.4.0
        autopep8                      1.6.0
        Babel                         2.10.1
        backcall                      0.2.0
        backports.functools-lru-cache 1.6.4
        beautifulsoup4                4.11.1
        bleach                        5.0.0
        brotlipy                      0.7.0
        certifi                       2022.5.18.1
        cffi                          1.15.0
        charset-normalizer            2.0.12
        colorama                      0.4.4
        control                       0.9.2
        cryptography                  37.0.2
        cycler                        0.11.0
        debugpy                       1.6.0
        decorator                     5.1.1
        defusedxml                    0.7.1
        dill                          0.3.5.1
        entrypoints                   0.4
        executing                     0.8.3
        fastjsonschema                2.15.3
        flake8                        4.0.1
        flit_core                     3.7.1
        fonttools                     4.33.3
        idna                          3.3
        importlib-metadata            4.11.4
        importlib-resources           5.7.1
        ipykernel                     6.13.1
        ipympl                        0.9.1
        ipython                       8.4.0
        ipython-genutils              0.2.0
        ipywidgets                    7.7.0
        isort                         5.10.1
        jedi                          0.18.1
        Jinja2                        3.1.2
        json5                         0.9.5
        jsonschema                    4.6.0
        jupyter-client                7.3.4
        jupyter-core                  4.10.0
        jupyter-lsp                   1.5.1
        jupyter-server                1.17.1
        jupyterlab                    3.4.3
        jupyterlab-lsp                3.10.1
        jupyterlab-pygments           0.2.2
        jupyterlab-server             2.14.0
        jupyterlab-widgets            1.1.0
        kiwisolver                    1.4.2
        lazy-object-proxy             1.7.1
        MarkupSafe                    2.1.1
        matplotlib                    3.5.2
        matplotlib-inline             0.1.3
        mccabe                        0.6.1
        mistune                       0.8.4
        mpmath                        1.2.1
        munkres                       1.1.4
        nbclassic                     0.3.7
        nbclient                      0.6.4
        nbconvert                     6.5.0
        nbformat                      5.4.0
        nest-asyncio                  1.5.5
        notebook                      6.4.12
        notebook-shim                 0.1.0
        numpy                         1.22.4
        packaging                     21.3
        pandocfilters                 1.5.0
        parso                         0.8.3
        pickleshare                   0.7.5
        Pillow                        9.1.1
        Pint                          0.19.2
        pip                           22.1.2
        platformdirs                  2.5.1
        pluggy                        1.0.0
        prometheus-client             0.14.1
        prompt-toolkit                3.0.29
        psutil                        5.9.1
        pure-eval                     0.2.2
        pycodestyle                   2.8.0
        pycparser                     2.21
        pydocstyle                    6.1.1
        pyflakes                      2.4.0
        Pygments                      2.12.0
        pylint                        2.14.1
        pyOpenSSL                     22.0.0
        pyparsing                     3.0.9
        PyQt5                         5.15.4
        PyQt5-sip                     12.9.0
        pyrsistent                    0.18.1
        PySocks                       1.7.1
        python-dateutil               2.8.2
        python-lsp-jsonrpc            1.0.0
        python-lsp-server             1.4.1
        pytz                          2022.1
        pywin32                       303
        pywinpty                      2.0.5
        pyzmq                         23.1.0
        requests                      2.28.0
        rope                          1.1.1
        scipy                         1.8.1
        Send2Trash                    1.8.0
        setuptools                    62.3.3
        sip                           6.5.1
        six                           1.16.0
        slycot                        0.4.0.0
        sniffio                       1.2.0
        snowballstemmer               2.2.0
        soupsieve                     2.3.1
        stack-data                    0.2.0
        sympy                         1.10.1
        terminado                     0.15.0
        tinycss2                      1.1.1
        toml                          0.10.2
        tomli                         2.0.1
        tomlkit                       0.11.0
        tornado                       6.1
        traitlets                     5.2.2.post1
        typing_extensions             4.2.0
        ujson                         5.3.0
        unicodedata2                  14.0.0
        urllib3                       1.26.9
        wcwidth                       0.2.5
        webencodings                  0.5.1
        websocket-client              1.3.2
        wheel                         0.37.1
        widgetsnbextension            3.6.0
        win-inet-pton                 1.1.0
        wrapt                         1.14.1
        yapf                          0.32.0
        zipp                          3.8.0
Command Line Output
[terminal_output.txt](https://github.com/jupyter-lsp/jupyterlab-lsp/files/8935103/terminal_output.txt)

Browser Output (recommended for all interface issues)
Paste the output from your browser JavaScript console replacing the text in here.

To learn how to open the developer tools in your browser:
https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools#How_to_open_the_devtools_in_your_browser
If too many messages accumulated after many hours of working in JupyterLab,
consider refreshing the window and then reproducing the bug to reduce the noise in the logs.

TomLXXVI commented 2 years ago

Since recently, the bug doesn't show up anymore. I think that a recent Windows update solved the issue for me.

thingumajig commented 1 year ago

I have a similar error with all operating system updates. The error occurs some time after the start of work. And Lsp server stops working.

A properly escaped repeating fragment of long long stacktrace:

{"jsonrpc":"2.0","id":1190,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///c:/projects/sequence-labeling/.virtual_documents/notebooks/parse_dataset.ipynb"},"position":{"line":116,"character":40}}}
    Traceback (most recent call last):
      File "C:\Users\artif\AppData\Local\pypoetry\Cache\virtualenvs\sequence-labeling-poy5HrIU-py3.10\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write
        await convert_yielded(self._write_one(response.encode("utf-8")))
      File "C:\Scoop\apps\python\current\lib\concurrent\futures\thread.py", line 58, in run
        result = self.fn(*self.args, **self.kwargs)
      File "C:\Users\artif\AppData\Local\pypoetry\Cache\virtualenvs\sequence-labeling-poy5HrIU-py3.10\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one
        self.stream.write(message)
    OSError: [Errno 22] Invalid argument
[E 2022-12-04 11:33:09.518 ServerApp] <LspStdIoWriter(parent=<LanguageServerSession(language_server=pylsp, argv=['C:\\Users\\xxxx\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\sequence-labeling-poy5HrIU-py3.10\\Scripts\\python.exe', '-m', 'pylsp'])>)> couldn't write message: Content-Length: 4645