abingham/emacs-ycmd

Ycmd server finished with exit code 9

Closed this issue · 13 comments

Hello all,

firstly I would like to thank you for this very handy tool.
Secondly I would need your help, in identifying a problem with emacs and ycmd. I used to be a very happy user until I updated with emacs package-list to the latest 20160828.434 from elpa. As far as I can see it corresponds to the latest commit 56808f9. For some unknown reason the server finishes with exit code 9 and I couldn't find a way to identify the exact problem.

Could you please provide some tips in order to further debug the issue.

The server works if I try to start it manually.
cd ycmd/ycmd;python __main.py__ --options_file some_config.json

The ycmd server is from master branch commit b3643ce

Thanks for any feedback.

ptrv commented

Hi @apmanol

The emacs-ycmd commit you mention is probably not the culprit, since the change is not very intrusive, just adding new keywords for rust-mode.

Is this happening for all your projects?

Can you post your emacs-ycmd configuration? and your ycm_extra_conf.py or global conf?

Which python version are you using? Did you recompile ycmd after you updated it?

Which emacs version are you using?

Thanks for answer!

The transition was from some version from two months ago (sorry I don't have the exact number) to the current one.
Yes, even for a simple int main(){return 0;}

(require 'ycmd)
(require 'company-ycmd)
(require 'flycheck-ycmd)
;; (require 'company-ycmd)

(company-ycmd-setup)
(flycheck-ycmd-setup)

;; Activate for editing C++ files
(add-hook 'c++-mode-hook 'ycmd-mode)
(add-hook 'c++-mode-hook 'company-mode)
(add-hook 'c++-mode-hook 'flycheck-mode)

;; Replace the directory information with where you downloaded ycmd to
(set-variable 'ycmd-server-command (list "python" (substitute-in-file-name "$HOME/Projects/Thirdparty/ycmd/ycmd/__main__.py")))

;; Edit according to where you have your Chromium/Blink checkout
(add-to-list 'ycmd-extra-conf-whitelist (substitute-in-file-name "$HOME/dev/blink/.ycm_extra_conf.py"))

;; Show flycheck errors in idle-mode as well
(setq ycmd-parse-conditions '(save new-line mode-enabled idle-change))

;; Makes emacs-ycmd less verbose
(setq url-show-status nil)

;; Set global conf
(set-variable 'ycmd-global-config "$HOME/Projects/Thirdparty/ycmd/ycm_global_conf.py")

;; Add yasnippet support for all company backends
;; https://github.com/syl20bnr/spacemacs/pull/179
(defvar company-mode/enable-yas t
  "Enable yasnippet for all backends.")

(defun company-mode/backend-with-yas (backend)
  (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
      backend
    (append (if (consp backend) backend (list backend))
            '(:with company-yasnippet))))

(setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))

ycm_global_conf_issue.zip

Python 2.7.11 (fedora 23)

Yes I recompiled the ycmd.

GNU Emacs 24.5.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.18.9)

ptrv commented

Hmm, you configuration looks pretty normal and I also tested your global ycm config file (which is the default one from ycmd?) You have also a project .ycm_extra_conf.py. Maybe there is something?

With this information I cannot do much or suggest anything. We need exact reproduction steps which we we can use to reproduce on our machines.

One recent major change though in emacs-ycmd was that we set the server port now in emacs-ycmd and not parse it from the server output. For this we have the function ycmd--get-unused-port.

Could you please try to set your server port manually by setting the variable ycmd-server-port to a free port? In this case the automatic port retrieval is bypassed.

Yes indeed is the default one, used to work perfectly before the upgrade. Tried it with an simple file in /tmp and got the same result.

I tried the trick by setting port 55434, still the same problem.

Furthermore, I succeed to print the args in main.py of ycmd and I got the following:
In ycmd-server

Args: Namespace(check_interval_seconds=600, host='127.0.0.1', idle_suicide_seconds=10800, keep_logfiles=True, log='debug', options_file='/tmp/ycmd-options3265T0y', port=55434, stderr=None, stdout=None)
debug
2016-08-30 16:39:18,156 - DEBUG - Global extra conf not loaded or no function YcmCorePreload
serving on http://127.0.0.1:55434

In Messages

REQUEST [error] Error (error) while connecting to http://127.0.0.1:55434/shutdown.
Ycmd server finished with exit code 9
ycmd--wait-until-server-ready: ERROR: Ycmd server timeout

The only strange thing is that I couldn't find the options_file in my filesystem, but I think it gets deleted on shutdown.

vheon commented

The only strange thing is that I couldn't find the options_file in my filesystem, but I think it gets deleted on shutdown.

The option file is deleted as soon as it's read by ycmd is used only to pass the secret for the HMAC authentication.

ptrv commented

The server output points to the /shutdown request from ycmd-close. Maybe we should wait longer before we send the /ready request.

@apmanol Could you please try this commit ptrv@44a0990 from this branch https://github.com/ptrv/emacs-ycmd/tree/get-port-from-server

With the patch we wait until we get the port from the server output before sending first ready request.

with the patch and empty ycmd-server-port:

From ycmd-server log:

Args: Namespace(check_interval_seconds=600, host='127.0.0.1', idle_suicide_seconds=10800, keep_logfiles=True, log='debug', options_file='/tmp/ycmd-options8559Nyn', port=0, stderr=None, stdout=None)
debug
sanity check ok
2016-08-31 09:43:25,313 - DEBUG - Global extra conf not loaded or no function YcmCorePreload
call global extra
detach from terminal
ready to run
serving on http://127.0.0.1:32919

From Messages log

REQUEST [error] Error (error) while connecting to http://127.0.0.1:32919/shutdown.
Ycmd server finished with exit code 9
progn: ERROR: Ycmd server timeout

ptrv commented

Hmm, very strange.

From the output it looks like the ycmd is not understanding the /shutdown request.

I could reproduce the same error message when changing the /shutdown to something mispelled like /shutdow.

The shutdown requst has been introduced in ycmd also quite recently.
Can you please verify again if ycmd is the latest, because for me it looks like you are not using the latest ycmd and the shutdown request is not understood by the server.

Unfortunately, I deleted the ycmd folder, cloned and rebuild but the problem remains.

Starting the server like this

cd /ycmd/ycmd
python __main__.py --host 127.0.0.1 --port 55556 --log debug --options_file /tmp/ycmd-options5646rvS

and http
http http://127.0.0.1:55556/shutdown

doesn't cause the server to exit.

ptrv commented

What is the value of the variable request-backend? We used to set it before the request to url-retrieve but because an error with non-ascii characters we use the value of request-backend as it is, in order to make it possible for the user to set it to either curl or url-retrieve.

If you haven't set it then it's probably curl. Maybe you could try to set it to url-retrieve

Finally, thanks for the excellent tip!

For some strange reason after coming back from vacation and upgrading both emacs packages and fedora packages the 'curl http://127.0.0.1:55556/shutdown` was trying to use the proxy settings.

After adding the 127.0.0.1 to no_proxy environment variable everything start working as it should.

Thanks again for your time and for maintaining this excellent tool.

ptrv commented

Ahhh, finally!
I am glad we could solve the issue. 😄

Happy completing!

ptrv commented

@apmanol Btw, you can view the log for the server communication by setting the variable request-log-level from it's default -1 (no logging) to one of error/warn/info/verbose/debug and opening the buffer <space>*request-log*. (notice the space before the star in the buffer name)