Subject: bug#61350: Eglot over Tramp freezes with large project

From: Michael Albinus <[email-masked]>
Date: Tue, 28 Feb 2023 13:59:19 +0100

João Távora <[email-masked]> writes:

Hi João,

>>> ...is it though? :-) Can a feature that hangs when presented with more
>>> data than usual (however one defines that) be considered stable?
>> Tramp supports ControlMaster since Emacs 24. Eglot is the first case
>> I've heard of problems. I don't deny it
>
> That could be because, as far as I understand, Eglot is the first
> "major" package to use the transparent (make-process ... :file-handler
> t) which, AFAIU, means that Eglot's process, which doesn't really
> transmit _that_ much data, is piped transparently through Tramp's
> process managing the remote file whose buffer M-x eglot is executed in.

Eglot is not the first user of this. But Eglot sends a huge amount of
data over the wire, which seems to trigger the problem.

For example, lsp-mode uses start-file-process-shell-command, which calls
under the hood make-process similarly.

>>>> It is essential. I have been beaten by many Tramp users to support it.
>>> I'd say something "essential" is something you can't live without.  But
>>> that doesn't seem to be the case here.
>> Ohh. You haven't seen how much Tramp has been blamed because it doesn't
>> support it out of the box.
>
> I understand, but it's the occasionally-exploding racecar all over
> again.  I understand your reasoning: you're betting that it's acceptable
> for the ocassionally-exploded user to learn opt-out for a slightly
> slower car.
>
> The thing is they will probably blame the steering wheel, Eglot,
> because -- Tramp being "transparent" -- that's what they see.
>
> Ideally, we would just fix this.  It would be nice to understand what
> actually happen and what information is lost, presumably to
> ControlMaster's gremlins.  I think bringing in Eli's knowledge of
> process.c internals could be beneficial here.

I'm not against changing Tramp, really. But first I must understand
what's the problem, and why a change will solve it. Without other
collateral damages.

> Here are some questions.  Apologies in advance if some of them are in
> the "FM".

The Tramp manual misses detailed implementation notes. On my TODO for
years, but it didn't happen until now.

> 1. When I open a single remote file on a remote host, I am creating
>    Tramp process, I presume.

Yes. In Tramp slang, this is the (main) connection process.

> 2. If I kill this buffer and re-visit it, is the Tramp process re-used
>    somehow or is a new one created?

The same connection process is used.

> 3. If I open another nearby file on the same host, I am sharing that
>    Tramp process?

Yes, as long as the remote identification (method, user, host) are the
same.

> 4. What about in a different host?

A new connection process. Also if just the method or user
changes. "/ssh::" and "/scp::" use different connection processes.

> 5. Is there any way to get an overview of which Tramp processes are
>    "responsible" for each set of remote files?

The so called connection buffers. This is always a buffer with the name
"*tramp/METHOD HOST*" or  "*tramp/METHOD USER@HOST*", depending whether
there is a user name, or not. See function tramp-buffer-name. The Tramp
connection processes are bound to these buffers.

> 6. Now if I M-x eglot in a Tramp remote file that I had been working on
>    Eglot-less for a while, is the Eglot process tunneled through the
>    existing Tramp process, reusing it, or is a new one started?

It depends. A synchronous process, created by process-file, is tunnelled
through the connection process. An asynchronous process, created by
make-process or start-file-process, is a new one.

> 7. If an existing process is reused, is there any way to force Tramp to
>    open a new one, perhaps with slightly different configuration
>    options?

No need for synchronous processes. And for asynchronous processes, they
have their own process. If configuration options are changed prior the
make-process call, they apply.

> João

Best regards, Michael.