Skip to content

fortls over tramp: fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\n #3369

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

Closed
2 of 3 tasks
XushanLu opened this issue Feb 24, 2022 · 3 comments · Fixed by #4204
Closed
2 of 3 tasks

fortls over tramp: fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\n #3369

XushanLu opened this issue Feb 24, 2022 · 3 comments · Fixed by #4204
Labels

Comments

@XushanLu
Copy link

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

I am having troubles using fortls over tramp. It keeps giving me the error information:

'Server fortls-remote:94034/starting exited with status exit(check corresponding stderr buffer for details). Do you want to restart it?'

I then opened the possible stderr buffer /tmp/fortls-remote-2-stderr on the remote machine and here is what I see:

Unexpected error: Line endings must be \r\n
Traceback (most recent call last):
File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/langserver.py", line 115, in run
request = self.conn.read_message()
File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/jsonrpc.py", line 110, in read_message
return self._receive()
File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/jsonrpc.py", line 95, in _receive
length = self._read_header_content_length(line)
File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/jsonrpc.py", line 81, in _read_header_content_length
raise JSONRPC2ProtocolError("Line endings must be \r\n")
fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\n

When trying to print what line is by changing line 82 of jsonrps.py

            raise JSONRPC2ProtocolError("Line endings must be \\r\\n")

to

            raise JSONRPC2ProtocolError("Line endings must be \\r\\n" + line)

I got fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\nContent-Length: 2682

I am using Spacemacs and here is my settings for fortls-remote in user-config:

  ;; Setting up lsp over tramp
  (require 'lsp)
  (lsp-register-client
   (make-lsp-client :new-connection (lsp-tramp-connection "fortls")
                    :major-modes '(f90-mode)
                    :remote? t
                    :server-id 'fortls-remote))

I also tried Doom Emacs but the same thing is happening. The version of fortls is 1.12.0 and I installed it by using pip provided by Anaconda if that matters.

Any idea? Really want to get this working cause my laptop has not have MPI installed and I rely on my remote servers for daily development. VScode works just fine and no issues like this. I am using Mac OS and Emacs 27. The remote is Unbuntu 20.04.

It rarely works but when it is working everything seems to be fine.

Steps to reproduce

  1. Start Spacemacs
  2. Open a tramp f90 buffer
  3. M-x lsp

Expected behavior

fortls-remote server is connected and everything is working.

Which Language Server did you use?

lsp-fortls

OS

MacOS

Error callstack

Error from stderr of fortls:
Unexpected error: Line endings must be \r\n
Traceback (most recent call last):
  File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/langserver.py", line 115, in run
    request = self.conn.read_message()
  File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/jsonrpc.py", line 110, in read_message
    return self._receive()
  File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/jsonrpc.py", line 95, in _receive
    length = self._read_header_content_length(line)
  File "/home/xsl/anaconda3/lib/python3.9/site-packages/fortls/jsonrpc.py", line 81, in _read_header_content_length
    raise JSONRPC2ProtocolError("Line endings must be \\r\\n")
fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\n

Anything else?

No response

@XushanLu XushanLu added the bug label Feb 24, 2022
@XushanLu
Copy link
Author

I could not believe it but it seems that adding

(setq lsp-print-io t)

seems to have solved the problem! Why?

@yyoncho
Copy link
Member

yyoncho commented Feb 24, 2022

@XushanLu if this is fixing your issue then you are hitting a well-known issue with lsp--send-message not being reentrant. I know that the fix is, I just don't have the time to fix it yet.

@XushanLu
Copy link
Author

Thanks for your response, @yyoncho!

Have played with it for 10 minutes but I think right now it is probably still unusable. Emacs hangs frequently. I think it may have something to do with my zsh (oh-my-zsh) although I have now removed most of the initialization in the .zshrc file when it detects TERM is dumb.

Switched back to local development and only use remote for compilation with lsp disabled. Unless I can make tramp faster, I don't think lsp works well for me remotely. It could easily be my .Spacemacs messing up with everything but I just don't have the time to figure things out.

yyoncho added a commit to yyoncho/lsp-mode that referenced this issue Oct 27, 2023
- This fixes the implementation of `lsp-mode` tramp support. After this PR the
remote clients will be automatically registered and in most of the cases it will
work out of the box. The remote connection is managed to a way similar to what
eglot does.

Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#3841
Fixes emacs-lsp#3642
Fixes emacs-lsp#3579
Fixes emacs-lsp#3530
Fixes emacs-lsp#3491
Fixes emacs-lsp#3490
Fixes emacs-lsp#3391
Fixes emacs-lsp#3369
Fixes emacs-lsp#3364
Fixes emacs-lsp#3020
Fixes emacs-lsp#3018
Fixes emacs-lsp#3020
yyoncho added a commit to yyoncho/lsp-mode that referenced this issue Oct 30, 2023
- This fixes the implementation of `lsp-mode` tramp support. After this PR the
remote clients will be automatically registered and in most of the cases it will
work out of the box. The remote connection is managed to a way similar to what
eglot does.

Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#3841
Fixes emacs-lsp#3642
Fixes emacs-lsp#3579
Fixes emacs-lsp#3530
Fixes emacs-lsp#3491
Fixes emacs-lsp#3490
Fixes emacs-lsp#3391
Fixes emacs-lsp#3369
Fixes emacs-lsp#3364
Fixes emacs-lsp#3020
Fixes emacs-lsp#3018
Fixes emacs-lsp#3020
@yyoncho yyoncho closed this as completed in d45aca0 Nov 1, 2023
yyoncho added a commit to yyoncho/lsp-mode that referenced this issue Nov 2, 2023
* Fix lsp-mode's tramp support

- This fixes the implementation of `lsp-mode` tramp support. After this PR the
remote clients will be automatically registered and in most of the cases it will
work out of the box. The remote connection is managed to a way similar to what
eglot does.

Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#4158
Fixes emacs-lsp#4150
Fixes emacs-lsp#3841
Fixes emacs-lsp#3642
Fixes emacs-lsp#3579
Fixes emacs-lsp#3530
Fixes emacs-lsp#3491
Fixes emacs-lsp#3490
Fixes emacs-lsp#3391
Fixes emacs-lsp#3369
Fixes emacs-lsp#3364
Fixes emacs-lsp#3020
Fixes emacs-lsp#3018
Fixes emacs-lsp#3020

* Use executable-find with remote = t everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants