eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
613 stars 145 forks source link

Language Server method call never ends #606

Closed kuldeeparora89 closed 2 years ago

kuldeeparora89 commented 2 years ago

I have created a Java-based LSP client, but none of the method calls are completed & it waits indefinitely.

Socket socket = new Socket("localhost", 6008);
Launcher<LanguageServer> createClientLauncher = LSPLauncher.createClientLauncher (languageClient,
                socket.getInputStream(), socket.getOutputStream());
LanguageServer server = createClientLauncher.getRemoteProxy();

createClientLauncher.startListening();
InitializeResult result = server.initialize(new InitializeParams()).get();

System.out.println("end");

initialize method never returns. The Language Server is working fine when tested with the VSCode instance.

Seems like requests are not reaching the server as nothing is printed in trace logs of the server.

Server Code -

Function<MessageConsumer, MessageConsumer> wrapper = consumer -> {
            MessageConsumer result = consumer;
            return result;
        };
        Launcher<LanguageClient> launcher = createSocketLauncher(languageServer, LanguageClient.class, new InetSocketAddress("localhost", 6008), Executors.newCachedThreadPool(), wrapper);
        languageServer.connect(launcher.getRemoteProxy());
        Future<?> future = launcher.startListening();
        while (!future.isDone()) {
            Thread.sleep(10_000l);
        }

What could be the issue here?

jonahgraham commented 2 years ago

Have you tried turning on the tracing? See trace argument to createLauncher: https://github.com/eclipse/lsp4j/blob/3a5cce9597fef1a53f98f6e9a5d21a34c8bfc757/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Launcher.java#L73

That may give some indication of the problem.

kuldeeparora89 commented 2 years ago

Yep both on client & server side, Client trace - [Trace - 03:06:52 PM] Sending request 'initialize - (1)' Params: { "processId": null, "rootUri": null }

Server side nothing.

jonahgraham commented 2 years ago

Your code looks correct to me - I would end up starting to see if any bytes are arriving on the server (debug it) and make sure you don't have a firewall blocking the traffic too. If you are on linux you can stick socat between the two so you can see what ends up on the "wire", or even manually prod the server that way.

kuldeeparora89 commented 2 years ago

Since both client & server running on localhost so I was not expecting any firewall-related issue, but the issue is the same after disabling the firewall. On server side code execution is getting stuck at below line int c = input.read(); under StreamMessageProducer.java

@Override
    public void listen(MessageConsumer callback) {
        if (keepRunning) {
            throw new IllegalStateException("This StreamMessageProducer is already running.");
        }
        this.keepRunning = true;
        this.callback = callback;
        try {
            StringBuilder headerBuilder = null;
            StringBuilder debugBuilder = null;
            boolean newLine = false;
            Headers headers = new Headers();
            while (keepRunning) {
                int c = input.read();
kuldeeparora89 commented 2 years ago

I got the issue , I had another client instance which was blocking the request of this client.

jonahgraham commented 2 years ago

Great - thanks for reporting back your resolution.