Subject: Re: bug#78791: 30.1; Tramp reopening file with sudo after disconnect error message

From: Michael Albinus <[email-masked]>
Date: Sun, 15 Jun 2025 09:11:45 +0200

Alexis Bakatine via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

Hi Alexis,

> Hello, when I'm trying to open a file from a Dired buffer with sudo after a
> disconnect with Tramp, it results in an error message.
>
> How to reproduce:
>
> 1. emacs -Q '/ssh:foo@bar|sudo::'
> 2. M-x tramp-cleanup-all-connections
> 3. 'o' or <RET> to open a file
>
> result in *Messages*:
> Host name 'bar' does not match ‘\`\(?:t480s\|\(?:127\.0\.0\.1\|::1\|ip\(?:6-lo\(?:calhost\|opback\)\|v6-lo\(?:calhost\|opback\)\)\|localhost[46]?\)\)\'’
>
> Note that when NOT using sudo as with /ssh:foo@bar:, I can run M-x
> tramp-cleanup-all-connections and open a file without problem,
> Tramp reconnects automatically.

This is not an error. It is expected behavior.

The notion '/ssh:foo@bar|sudo::' is called ad-hoc multi-hop for a reason
in the Tramp manual. If you open it, you will see a dired buffer like
"/sudo:root@bar:~/" - note, that the leading "/ssh:foo@bar:" part is not
contained there. Tramp knows internally, that it should use this first
hop when accessing "/sudo:root@bar:".

However, when you call tramp-cleanup-all-connections, this information
is removed (by intention, in order to cleanup). When you reopen a file,
"/sudo:root@bar:" cannot be connected again due to the missing first hop
information.

The Tramp manual discusses this case, see (info "(tramp) Ad-hoc multi-hops")

--8<---------------cut here---------------start------------->8---
   Ad-hoc definitions are removed from ‘tramp-default-proxies-alist’ via
the command ‘M-x tramp-cleanup-all-connections <RET>’ (*note Cleanup
remote connections::).
--8<---------------cut here---------------end--------------->8---

I recommend you to set either tramp-show-ad-hoc-proxies or
tramp-save-ad-hoc-proxies to t.

> Best regards,
> Alexis

Best regards, Michael.