Sonarlint connection to sonarqube failing but also not?

Please provide

  • Operating system: Windows 11
  • SonarLint plugin version: 4.12.0
  • Programming language you’re coding in: C/C++
  • Is connected mode used: yes
    • Connected to SonarCloud or SonarQube (and which version): 9.9

And a thorough description of the problem / question:

Hi, I would like to run SonarLint in connected mode with our SonarQube 9.9 server. But when I set this up I get the following error:

Client SonarLint Language Server: connection to server is erroring. Shutting down server.
Sending request 'shutdown - (2)'.
Stopping server timed out
Stopping server failed
Error: Stopping the server timed out
	at /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-4.12.0/dist/extension.js:2:881069

I get the last message a few times before all logs stop.

When I check SonarQube (in the security section of my profile) I see that the last connection my account made was when SonarLint tried to connect.

I have already enabled verbose logging hoping to see more information, but sadly nothing new about failing to connect.

EDIT
Enabling more log settings gave me the following additional errors:

Client SonarLint Language Server: connection to server is erroring. Shutting down server.
... (repeated hunderds of times)
org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Read end dead 
... (repeated hunderds of times)
Stopping server timed out
Stopping server failed
Error: Stopping the server timed out
	at /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-4.12.0/dist/extension.js:2:881069
	at runNextTicks (node:internal/process/task_queues:60:5)
	at process.processTimers (node:internal/timers:511:9)
... (repeated hunderds of times)
org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Read end dead
... (repeated hunderds of times)
Client SonarLint Language Server: connection to server is erroring. Shutting down server.
1 Like

Hey there @strife9129, thanks for reporting this!

It is very strange and the first time I’ve seen such logs :smiley: I think the problem here is not the connection to your SonarQube Server, but rather a connection of SonarLint client to the SonarLint Language Server (its backend), which is worse :melting_face:

Do you have any special User Settings in your VS Code? Do I understand correctly that you see this as soon as the VS Code window starts up?

Thanks in advance,
Sophio :bowing_woman:

Hi @sophio.japharidze,

No I do not have any special User Settings in my VS code, however I’m on a corporate network with pretty heavy restrictions, so could explain it, however cannot confirm at the moment. And no I do not see these longs (above) as soon as I open up VS code, i see the following (a lot of them, so i just picked a few that might be interesting):

[Trace - 8:24:59 AM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "[Info - 08:24:59.570] SonarLint backend started, instance=org.sonarsource.sonarlint.core.rpc.impl.SonarLintRpcServerImpl@14028087"
}
...
[Trace - 8:24:59 AM] Received response 'initialize - (0)' in 582ms.
Result: {
    "capabilities": {
        "textDocumentSync": {
            "openClose": true,
            "change": 1
        },
        "notebookDocumentSync": {
            "notebookSelector": [
                {
                    "notebook": "jupyter-notebook",
                    "cells": [
                        {
                            "language": "python"
                        }
                    ]
                }
            ]
        },
        "codeActionProvider": true,
        "executeCommandProvider": {
            "commands": [
                "SonarLint.QuickFixApplied",
                "SonarLint.OpenRuleDescCodeAction",
                "SonarLint.OpenStandaloneRuleDesc",
                "SonarLint.BrowseTaintVulnerability",
                "SonarLint.ShowTaintVulnerabilityFlows"
            ],
            "workDoneProgress": true
        },
        "workspace": {
            "workspaceFolders": {
                "supported": true,
                "changeNotifications": true
            }
        }
    },
    "serverInfo": {
        "name": "SonarLint Language Server",
        "version": "3.12.0.75621"
    }
}
...
[Trace - 8:25:05 AM] Sending response 'sonarlint/listFilesInFolder - (5)'. Processing request took 4450ms
Result: {
    "foundFiles": [
         ....
         {
            "fileName": "name.hpp",
            "filePath": "/workspaces/path/name.hpp",
            "content": null
        },
        ...
    ]
}

I guess the SonarLint Language Server is not hosted by our SonarQube but a stand alone system managed by SonarSource?

What port will Sonarlint try to use to communicate with its backend? And does SonarLint support a proxy?

Regards,

Wesley

1 Like

:thinking:

Are you using any kind of remote workspace? Anything like SSH, WSL, dev container …

Language Server is shipped with the extension and runs on the same machine as VS Code in the local environment. If you are using a remote setup, the Language Server will run on the remote machine, and the errors could be due to poor connection/network restrictions between your local machine and the container running the Language Server.

Yes, I’m running on a dev container with the extension installed on the dev container (via devcontainers.json). However I see the same errors when I close the dev container and run it directly on the host.

Does the Language server run on docker? Since you say “container”. I do not see any container running on my Rancher desktop.

Does the Language server run on docker?

As per VS Code documentation

  • Workspace Extensions [SonarLint in this case]: These extensions are run on the same machine as where the workspace is located. When in a local workspace, Workspace Extensions run on the local machine. When in a remote workspace or when using Codespaces, Workspace Extensions run on the remote machine / environment. Workspace Extensions can access files in the workspace to provide rich, multi-file language services, debugger support, or perform complex operations on multiple files in the workspace (either directly or by invoking scripts/tools). While Workspace Extensions do not focus on modifying the UI, they can contribute explorers, views, and other UI elements as well.

Could you please share your entire logs? I can initiate a private conversation if you don’t want to share them publicly.

All the best,
Sophio

Due to security concerns I wont be able to share the entire logs, hope you understand. If you can indicate what you are looking for I’m more then willing to share that with you.

Regards,

Wesley

OK, I understand.

I tried to reproduce an issue on a Windows machine by using SonarLint in a DevContainer and I did not face any issues. If possible, I am interested to see the logs right before and after

Client SonarLint Language Server: connection to server is erroring. Shutting down server.
... (repeated hunderds of times)
org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Read end dead 
... (repeated hunderds of times)
Stopping server timed out

In case there is any request or analysis that may be causing the issue. Also, do you have any memory limit set in your devcontainers.json ?

Thanks in advance,
Sophio

I think I managed to find the issue, by dumb luck. In the global settings.json from VScode sonarlint put the following information when I made the connection to our SonarQube server:

"sonarlint.connectedMode.connections.sonarqube": [
    {
        "serverUrl": "https://a.dev.example.com",
        "connectionId": "https-a-dev-example-com"
    }
],

I removed the key value pair “connectionId” and since then I no longer see the errors. howerver I do now notice that I get a popup if i want to configure a binding between the local project and the SonarQube server:


When I press the “configure binding” button I notice that the connection to the language server gets broken (I see the errors) and only after removing the settings does the connection get restored (I reload the devcontainer to make sure).

It (SonarLint) has now been running (when I post this) for about 15 minutes while before it crashed in a minute or 2.

1 Like

This is very strange, I cannot see why it would be related at all.

As I understand, SonarLint now works without crashing if you remove all connection and binding settings.

Could you try to remove the connection completely via SonarLint > Connected Mode > SonarQube > connection > Remove 🗑️ button? Then, go to the workspace settings > my-folder/.vscode/settings.json and make sure that there is no "sonarlint.connectedMode.project" setting present.

Finally, try recreating the connection and the binding as per normal instructions.

If that does not work it means there might be a connection problem between your Dev Container host and your SonarQube server.

Sorry I’m not a huge help here, it’s a very niche scenario :smiley:
Sophio

Its very weird, and I have no clue why it would do this. Thats why I said I “fixed” it with absolute dumb luck.

No I still have a connection to our SonarQube server, I also checked the security section of my account and see that I made a connection when I started the DevContainer. I only removed the “connectionId” key value pair, the “serverUrl” key value pair was still there. (hind side, this does remove the project binding).

After creating the connection again everything ran fine, untill I created a project binding. This project binding was made when I was running it via a DevContainer. After doing so the connection to the language server is quite immediately broke. Not only when I’m running on a DevContainer, but also when I have the project open directly on the host. (project A)

I also had another project open, which had no binding yet (connected to SonarQube, but no project binding) and that one kept on running without a problem. (project B)

Too eliminate a potential issue with the DevContainer I recreated the project binding for project A while it was NOT connected to a remote (DevContainer). After doing so it broke again! So while its running on the host and when its running on a DevContainer it will break :confused:

After removing the project binding (via the UI) and trying to create the connection again (via the UI) I was greeted with this error:
afbeelding
To create the project binding again I have to restart visual studio code to create the project binding once again.

To confirm that its NOT an issue with a DevContainer I have found an error log that my colleague made 2/3 months ago before he switched over to a DevContainer. He also used a different version:

[Error - 4:58:03 PM] Client SonarLint Language Server: connection to server is erroring. Shutting down server.
[stderr] org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Read end dead
[stderr] org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.io.IOException: Read end dead
[Error - 4:58:04 PM] Stopping server timed out
[Error - 4:58:04 PM] Stopping server failed
Error: Stopping the server timed out
	at c:\Users\ME\.vscode\extensions\sonarsource.sonarlint-vscode-4.11.0-win32-x64\dist\extension.js:2:878493

I completely understand that you do not know why this issue is here! its very weird.

tldr (since its a information dump):
SonarLint runs fine on the host and on a DevContainer if there is no project binding. The moment a project binding is created (either via the host or DevContainer) it will break.

Thanks for the additional information.

Yes removing the connectionId from the connection “worked” for you because it actually broke the binding :smiley:

You asked before:

does SonarLint support a proxy?

Is your SonarQube Server behind a proxy? Currently, SonarLint does not support this out-of-the-box, but maybe you could give either this or this a try In order to pass proxy configuration to the SonarLint Language Server (java backend).

Trying it on your machine first (not a DevContainer) could give you higher chances of success :see_no_evil:

Looking forward to hearing the update,
Sophio

The question was more related to software that SecOps manages on my laptop. But since it looks like the connection to SonarQube it self is working, there is no conflict there I suppose. But ofcourse I will have a look at this, but personally proxies are black magic for me :sweat_smile: :see_no_evil:.

So will need to figure that out. In the mean time if you or your colleagues have any idea’s or even tests that I may run please let me know!

regards,

Wesley

1 Like

So it seems setting a proxy indeed fixed the issue that I was having although gave me new onces. I used the following setting in my user settings.json file of VS code.

"sonarlint.ls.vmargs": "-Djava.net.useSystemProxies=true",

After saving and restarting VS code I noticed that the connection to SonarQube takes quite long, too long. At a moment I get the error “internal error”, but yet I see a yellow checkmark next to the SonarQube server in VS code. And then I want to select a project to bind too I do see a list of all the possible projects.

Once I have setup the appropriate connection made with the project I do not see any weird errors, nor do I see anything showing up in the security hotspot section within SonarLint which I suspected it would.

Please send me a message personally so I can send these logs to you. Thank you.

So one of my colleagues got SonarLint working on Intellij and to get this working he specified the locally hosted .pac file in intelij. Within VScode I do not see this option right out of the box, however I found that you can add it via a command line flag:

So I changed the target property of the Visual Studio Code shortcut, and now it looks like this:

"C:\Users\ME\AppData\Local\Programs\Microsoft VS Code\Code.exe" --proxy-pac-url=http://127.0.0.1:9000/systemproxy-xxxxxx.pac

I also removed the proxy setting in the extension vmargs setting. I still have connection to the server, and do not notice any delay. However when I bind the project I once again face the same issue.

Hello,

Thanks a lot for the additional information! Indeed, it is possible to pass the path to the .pac file to VS Code, but this will be applied to the VS Code process only and for “native” features like auto-update of extensions, VS Code telemetry, etc., as mentioned in the linked document (thanks for that btw!). Unlike IntelliJ, those settings are not propagated, and even in some cases not available at all for the extensions :cry:

As I said above, SonarLint for VS Code does not officially support Connected Mode setup with proxy. We do have a ticket for it, but due to the variety of proxies, auth options, etc., it has not yet been properly specified nor implemented.

The SonarLint setting that was linked is a kind of workaround that works for some cases but not all. I found this old thread with a similar problem to yours. I think if you make sure that the PAC file you are using is applied in the system network configuration, and then you tell SonarLint to use system settings like you did here, it could help.

At the same time, I am flagging this for our product team for further prioritization.
I appreciate your patience and willingness to collaborate throughout all these replies. :bowing_woman:
All the best,
Sophio

I just found this thread on vscode’s github page. Might be an interesting one to keep in mind, sadly not a solution for the moment tho: