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

"The JSON-RPC connection with the remote party was lost before the request could complete." #1982

Closed
pbiggar opened this issue Nov 26, 2021 · 11 comments

Comments

@pbiggar
Copy link
Contributor

pbiggar commented Nov 26, 2021

Using the latest version of ionide in VSCode (5.10.1), I am not able to save+format files. I get the following error in the F# output tab in VSCode when saving:

[Error - 9:28:33 PM] Request textDocument/formatting failed.
  Message: One or more errors occurred. (One or more errors occurred. (The JSON-RPC connection with the remote party was lost before the request could complete.))
  Code: -32603 
[21:28:33.122 WRN] [Fantomas] Errors while formatting file, defaulting to previous content. Error message was One or more errors occurred. (One or more errors occurred. (The JSON-RPC connection with the remote party was lost before the request could complete.))
System.AggregateException: One or more errors occurred. (One or more errors occurred. (The JSON-RPC connection with the remote party was lost before the request could complete.))
 ---> System.AggregateException: One or more errors occurred. (The JSON-RPC connection with the remote party was lost before the request could complete.)
 ---> StreamJsonRpc.ConnectionLostException: The JSON-RPC connection with the remote party was lost before the request could complete.
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync(JsonRpcRequest request, Type expectedResultType, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Fantomas.Client.LSPFantomasService.Fantomas-Client-Contracts-FantomasService-FormatDocumentAsync@200-1.Invoke(Task`1 t) in C:\Users\fverdonck\Projects\fantomas\src\Fantomas.Client\LSPFantomasService.fs:line 200
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---

This is after ionide offers me a "local" or "global" install, and choose the global install.

Weirdly, I also found some odd files in my filesystem, that seem to have been created by a misbehaving command somewhere in VSCode/ionide/fantomas:

 $ find . | grep daemon
./fsharp-backend/src/ApiServer/--daemon
./fsharp-backend/src/Prelude/--daemon
./fsharp-backend/src/BwdServer/--daemon
16:20:30 torres ~/projects/dark [paul/fstodo-pass]
 $ find . | grep fantomas
./fsharp-backend/src/Wasm/fantomas
./fsharp-backend/src/ApiServer/fantomas
./fsharp-backend/src/Prelude/fantomas
./fsharp-backend/src/BwdServer/fantomas

That is to say, in each project in my .NET solution, there are now two empty directories, named "fantomas" and "--daemon".

I'm not sure if it's related, but I also have a fantomas executable in my path, which the plugin does not seem to pickup.

@pbiggar
Copy link
Contributor Author

pbiggar commented Nov 26, 2021

I'm now realizing this might not be the right repo to report this. Should it go in the FSAC or ionide-vscode repos instead?

@nojaf
Copy link
Contributor

nojaf commented Nov 27, 2021

Hey Paul, thank you for this report.

There are issues open at the other repositories but there is a strongly related component to this one, so perfectly fine to discuss here.

The JSON-RPC connection with the remote party was lost before the request could complete.

This is an interesting one, it means Fantomas.Client (used by fsautocomplete) cannot connect to your local or global fantomas-tool. This works like a charm on Windows but for some reason, it fails horribly on other OS'es.
I saw it working (during a screen share session) with a colleague on Ubuntu earlier this week, so there is still some guesswork about what is causing this.

The other interesting thing you mention is that fantomas and --daemon folders are being created. Most likely in the parent folder of the file, you tried to format.
Inside Fantomas.Client we do actually run the command fantomas --daemon to spawn the Fantomas process, which will then accept the formatting requests (via JSON-RPC).

So, it seems like launching the Fantomas process is not working out.
At the time of writing, the latest Ionide is not using the latest Fantomas.Client version (See ionide/FsAutoComplete#864).
Maybe, just maybe the newer version helps there, as some small tweak was made in the ProcessStartInfo (See commit).
This might help, although I doubt it.
Could you try and download 0.4.0 and replace Fantomas.Client.dll in your vscode ionide extension folder. (I would keep the old file though).

I really want to get to the bottom of this, but being unable to reproduce the problem, it really remains a needle in the hay.
Would you be interested in setting up a screen-share session perhaps, so we can troubleshoot it together?

@nojaf
Copy link
Contributor

nojaf commented Nov 27, 2021

Oh and /cc @baronfel

@pbiggar
Copy link
Contributor Author

pbiggar commented Nov 27, 2021

@nojaf Yeah, that would be great. If zoom works for you, I have a calendly to make this easy to schedule: [redacted as this has now been scheduled]

@nojaf
Copy link
Contributor

nojaf commented Nov 30, 2021

Yesterday @pbiggar and I had a zoom session where I could witness firsthand what wasn't working out.
Three things came up:

  • We currently don't support installed version via a --tool-path folder.
  • We assume the global tools are present on the PATH, while we should use the absolute path to the installed global tool.
  • As a last resort, we should try any fantomas executable on the PATH. Here we check if the version is compatible and if so, we use that version.

I believe the last two points should be tackled as --tool-path dates from a time where a .NET tool manifest wasn't a thing yet.
And by accepting any fantomas on the PATH (as last resort), people can provide their own workaround to still use a downloaded version from the --tool-path.

When finding the correct daemon for a given file path the following strategy should be used:

  • Find the local tool (dotnet tool list in parent directory, version found => dotnet fantomas)
  • Find the global tool (dotnet tool list -g, version found => "C:\Users\nojaf.dotnet\tools\fantomas.exe")
  • Try fantomas --version on the PATH, if compatible start: fantomas --daemon.

@nojaf
Copy link
Contributor

nojaf commented Dec 1, 2021

Hello @pbiggar, I've published a new version of Fantomas.Client (https://www.nuget.org/packages/Fantomas.Client/0.5.0) that should check the PATH as a last resort to find a compatible daemon.

Could you download this NuGet package and throw the Fantomas.Client.dll into the bin folder of the ionide install and see what this does?
I recall from our call that you had a script to launch Fantomas, I'm really sure what you had again but the fantomas file should be on the PATH for this to work. Could you tell me again what that exactly was?

@pbiggar
Copy link
Contributor Author

pbiggar commented Dec 2, 2021

I recall from our call that you had a script to launch Fantomas, I'm really sure what you had again but the fantomas file should be on the PATH for this to work. Could you tell me again what that exactly was?

I had installed fantomas with dotnet tool install fantomas-tool ~tool-path ~/bin, added ~/bin to my PATH, and I called fantomas using the path as <some list command> | xargs fantomas.

Here's the script and here's the install step (with the change I made after our call).

@nojaf
Copy link
Contributor

nojaf commented Dec 2, 2021

Ok, in this case, I'm expecting this actually to work just because you have it installed globally.
Please let me know if so.

@pbiggar
Copy link
Contributor Author

pbiggar commented Dec 2, 2021

Yeah, it now works because I switched to installing globally

@nojaf
Copy link
Contributor

nojaf commented Dec 3, 2021

Alright, good to hear. Can we close this issue then?

@pbiggar
Copy link
Contributor Author

pbiggar commented Dec 3, 2021

Yeah, looks like everything is handled in other issues. Thanks again!

@pbiggar pbiggar closed this as completed Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants