https://bugs.kde.org/show_bug.cgi?id=522883

            Bug ID: 522883
           Summary: Some LSP servers exit immediately on Flatpak kate
    Classification: Applications
           Product: kate
      Version First Git
       Reported In:
          Platform: Flatpak
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 194166
  --> https://bugs.kde.org/attachment.cgi?id=194166&action=edit
vstls strace log

When using Flatpak kate while the LSP is installed outside the sandbox, servers
like typescript-language-server, vscode-html-language-server,
vscode-css-language-server and vtsls terminate right after startup. Kate tries
to restart the server but it terminates again. After that, the output panel
shows "[LSP Client Warning] Server terminated unexpectedly ... NOT Restarting".
clangd and rust-analyzer worked fine on the same setup.

I strace'd one of the crashing servers to see what's happening. It wasn't
actually crashing, it called kill(2, 0), got EPERM, then sent SIGTERM to it's
own child processes and exited. So the server is terminating itself based on a
check against PID 2.

I found that a bunch of LSP poll a "processId" value sent by the client on the
initialization request to detect if the editor is closed and terminates itself.
Since flatpak sandboxes run in their own PID namespace, kate's PID inside the
sandbox is always 2. Which gets sent to the LSP. But from the outside PID 2
often corresponds to "kthreadd". So the server check fails and it assumes the
editor is closed.

I also found that GNOME builder hit the exact same problem and fixed it by not
sending processId at all:
https://gitlab.gnome.org/GNOME/gnome-builder/-/work_items/2050
https://gitlab.gnome.org/GNOME/gnome-builder/-/commit/f40310ab74e9e810371a8be45e113ee2280679f7

I tried the equivalent change in kate's lspclientserver.cpp (just commenting
out the processId field) and it fixed the issue for the servers I tested.

STEPS TO REPRODUCE
1. Install kate via flatpak.
2. Install an LSP server outside the flatpak sandbox. e.g.
typescript-language-server, vscode-html-language-server
3. Open a matching file that invokes the installed LSP.

OBSERVED RESULT
Server starts, does it's initial analysis and then quits:
[LSP Client Warning] Server terminated unexpectedly ... NOT Restarting

EXPECTED RESULT
Server stays running.

MY FIX
diff --git a/addons/lspclient/lspclientserver.cpp
b/addons/lspclient/lspclientserver.cpp
index 8ae721df1d..a4dc979508 100644
--- a/addons/lspclient/lspclientserver.cpp
+++ b/addons/lspclient/lspclientserver.cpp
@@ -1853,7 +1853,7 @@ private:
         // NOTE a typical server does not use root all that much,
         // other than for some corner case (in) requests
         auto root = mapPath(m_root, true);
-        QJsonObject params{{QLatin1String("processId"),
QCoreApplication::applicationPid()},
+        QJsonObject params{/*{QLatin1String("processId"),
QCoreApplication::applicationPid()},*/
                            {QLatin1String("rootPath"), root.isValid() ?
root.toLocalFile() : QJsonValue()},
                            {QLatin1String("rootUri"), root.isValid() ?
QJsonValue(QString::fromUtf8(root.toEncoded())) : QJsonValue()},
                            {QLatin1String("capabilities"), capabilities},

I don't know the codebase well enough to know if just commenting out the
"processId" field for all LSP is a good idea. But this is something that worked
for me.

SOFTWARE/OS VERSIONS
Operating System: KDE Linux 202607090946
KDE Plasma Version: 6.7.80
KDE Frameworks Version: 6.29.0
Qt Version: 6.11.1
Kate: flatpak (git)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to