merlin server hangs after interrupting command with no EOF
Bug occurs on my mac, I didn't try it on different machines.
Reproduction:
- Open terminal
- Check ocaml version, works fine:
rafal@machine ~ % ocamlmerlin server -version
The Merlin toolkit version v4.9-414, for Ocaml 4.14.1
- Run incomplete server command
rafal@machine ~ % ocamlmerlin server errors - Oh no, it doesn't do anything. Interrupt with ctrl+c.
- Run
ocamlmerlin server -versiononce again and see that it hangs
Full listing:
rafal@machine ~ % ocamlmerlin server -version
The Merlin toolkit version v4.9-414, for Ocaml 4.14.1
rafal@machine ~ % ocamlmerlin server errors
^C
rafal@machine ~ % ocamlmerlin server -version
Additional observation: It seems that the problem lays in handling of SIGINT. When I used ctrl+d (EOF) on command I get an empty json response and server works correctly afterwards:
rafal@machine ~ % ocamlmerlin server errors
{"class":"return","value":[],"notifications":[],"timing":{"clock":2041,"cpu":5,"query":0,"pp":0,"reader":0,"ppx":0,"typer":4,"error":0}}
rafal@machine ~ % ocamlmerlin server -version
The Merlin toolkit version v4.9-414, for Ocaml 4.14.1
Yes, ctrl-d is the normal way to end the command since Merlin is waiting for the content of the buffer to be provided on standard input. But sending SIGINT should not end in an unusable server (and actually it kind of breaks vscode's terminal too).
another observation: I tried different way of providing input with no EOF, and it handles SIGINT correctly:
rafal@machine ~ % (echo "" && cat) | ocamlmerlin server errors
^C
{"class":"return","value":[],"notifications":[],"timing":{"clock":755,"cpu":4,"query":0,"pp":0,"reader":0,"ppx":0,"typer":4,"error":0}}
So, how do you "repair" ocamlmerlin after it has been broken? I cannot edit any ocaml files now :disappointed:
You need to kill ocamlmerlin server process
OK, but it seems that it was not enough: I also had to remove /tmp/ocamlmerlin_1000_2050_26383789.socket to make it works again.
Anyway, thank you very much for your answer :+1:
The problem happens to me when opening a particular file. My editor (vim) calls both:
$ ocamlmerlin server check-configuration -filename my_file.ml
and
$ ocamlmerlin server errors -filename my_file.ml
Both commands, run from the terminal freeze so I have to stop them with ^C and then any ocamlmerlin command hangs.
To make it work again, I have to:
$ pkill -e ocamlmerlin
$ rm /tmp/ocamlmerlin_*.socket
Then, it works again:
$ ocamlmerlin server -version
The Merlin toolkit version v4.8-414, for Ocaml 4.14.1
Unfortunatly, I cannot show my_file.ml here, but I'll try to investigate what is special about it.
So, it is not related to the file content, but to its location. In some place, I get:
$ ocamlmerlin server errors -filename test.ml
{"class":"return","value":[{"type":"config","sub":[],"valid":true,"message":"No config found for file test.ml. Try calling `dune build`."}],"notifications":[],"timing":{"clock":3682,"cpu":5,"query":0,"pp":0,"reader":0,"ppx":0,"typer":5,"error":0}}
and if I move the file somewhere else, it hangs (and I have to ^C, and then ocamlmerlin-server is broken)
At last, I found the problem (but did not understand it) : the reason was these lines in my .merlin file:
S ../../some_dir/**
B ../../some_dir/**
that I manage to replace by more precise paths, without using **, and it works now.
Anyway, whatever the reason is, it would be nice if it could avoid breaking the server.
wow, thanks for thorogh research. I'll try to analyse your example. one idea that I came up with is that you can try to use ctrl+d instead of ctrl+c. can you please try if it works for you?
No, it does not work.
I also found out that it is faster to make tests with:
$ cat my_file.ml | ocamlmerlin single errors -dot-merlin .merlin | jq
since all you have to do is Ctrl-C when it hangs, but at least, it does not break anything else, so no need to pkill and rm.
$ cat my_file.ml | ocamlmerlin single errors -dot-merlin .merlin | jq
Yes, piping the file's content to Merlin is the correct way to use the cli. A command such as this one should never hang. It would be great if we could have a small reproduction case for this.
Did removing the ** actually solved your issue ?
Yes, it did solve the issue.