* bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory
@ 2022-03-24 7:15 Dima Kogan
2022-03-25 16:23 ` Michael Albinus
0 siblings, 1 reply; 4+ messages in thread
From: Dima Kogan @ 2022-03-24 7:15 UTC (permalink / raw)
To: 54542
Hi. This sounds convoluted, but it's a real-life bug I hit repeatedly.
Recipe:
1. emacs -Q
2. C-x C-f /ssh:host:directory
Visit some remote directory via TRAMP. This opens a dired buffer
3. Unplug the network cable. Or walk away from wifi. Or turn off the
remote host. Optionally, do other stuff with emacs. The bug is hit if
the buffer in step 2 is open somewhere; doesn't have to be visible
4. C-x C-f /some/local/directory
One would expect step 4 to work just fine because it's a local
directory, so no TRAMP business should affect it, but it does. Step 4
will try to connect to the host in step 2. But that host is gone, so
it'll fail, and step 4 will fail too.
The problem is here:
(defun dired-find-buffer-nocreate (dirname &optional mode)
....
(let (found (blist dired-buffers))
...
(while blist
...
(with-current-buffer (cdr (car blist))
....
(expand-file-name
(if (consp dired-directory)
(car dired-directory)
dired-directory))))
Here dired is trying to figure out if we're already visiting the
requested directory. In doing so, it loops through all extant dired
buffers, and runs (expand-file-name) on each one. Running
(expand-file-name) on a remote directory will try to contact the host.
I'm not attaching a patch because I'm not 100% sure what's appropriate.
I guess we want to replace
(expand-file-name dired-directory)
with something like this pseudo-code
(concat (tramp-host dired-directory)
(expand-file-name (tramp-filename dired-directory)))
Except, thinking about edge cases: making sure this works with/without
TRAMP, making sure relative directories work right, etc, etc.
Do we already have a function that does this?
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory
2022-03-24 7:15 bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory Dima Kogan
@ 2022-03-25 16:23 ` Michael Albinus
2022-03-25 23:15 ` Dima Kogan
0 siblings, 1 reply; 4+ messages in thread
From: Michael Albinus @ 2022-03-25 16:23 UTC (permalink / raw)
To: Dima Kogan; +Cc: 54542
[-- Attachment #1: Type: text/plain, Size: 2182 bytes --]
Dima Kogan <dima@secretsauce.net> writes:
Hi Dima,
> 1. emacs -Q
>
> 2. C-x C-f /ssh:host:directory
>
> Visit some remote directory via TRAMP. This opens a dired buffer
>
> 3. Unplug the network cable. Or walk away from wifi. Or turn off the
> remote host. Optionally, do other stuff with emacs. The bug is hit if
> the buffer in step 2 is open somewhere; doesn't have to be visible
>
> 4. C-x C-f /some/local/directory
>
> One would expect step 4 to work just fine because it's a local
> directory, so no TRAMP business should affect it, but it does. Step 4
> will try to connect to the host in step 2. But that host is gone, so
> it'll fail, and step 4 will fail too.
>
> The problem is here:
>
> (defun dired-find-buffer-nocreate (dirname &optional mode)
> ....
> (let (found (blist dired-buffers))
> ...
> (while blist
> ...
> (with-current-buffer (cdr (car blist))
> ....
> (expand-file-name
> (if (consp dired-directory)
> (car dired-directory)
> dired-directory))))
>
> Here dired is trying to figure out if we're already visiting the
> requested directory. In doing so, it loops through all extant dired
> buffers, and runs (expand-file-name) on each one. Running
> (expand-file-name) on a remote directory will try to contact the host.
>
> I'm not attaching a patch because I'm not 100% sure what's appropriate.
> I guess we want to replace
>
> (expand-file-name dired-directory)
>
> with something like this pseudo-code
>
> (concat (tramp-host dired-directory)
> (expand-file-name (tramp-filename dired-directory)))
>
> Except, thinking about edge cases: making sure this works with/without
> TRAMP, making sure relative directories work right, etc, etc.
>
> Do we already have a function that does this?
We have already variable non-essential, which shall help for
non-existing / broken connections. While I could reproduce your initial
recipe locally, the attached patch cures it for me. Could you, please,
test?
> Thanks!
Best regards, Michael.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1292 bytes --]
diff --git a/lisp/dired.el b/lisp/dired.el
index 3790197f66..a97604c4a0 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1272,6 +1272,7 @@ dired-find-buffer-nocreate
;; This differs from dired-buffers-for-dir in that it does not consider
;; subdirs of default-directory and searches for the first match only.
;; Also, the major mode must be MODE.
+ (let ((non-essential t))
(if (and (featurep 'dired-x)
dired-find-subdir
;; Don't try to find a wildcard as a subdirectory.
@@ -1304,7 +1305,7 @@ dired-find-buffer-nocreate
(setq found (cdr (car blist))
blist nil)
(setq blist (cdr blist))))))
- found)))
+ found))))
\f
;;; Read in a new dired buffer
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index fd18b3f05c..805be8270a 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -4957,6 +4957,7 @@ tramp-maybe-open-connection
;; If Tramp opens the same connection within a short time frame,
;; there is a problem. We shall signal this.
(unless (or (process-live-p p)
+ (and (processp p) (not non-essential))
(not (tramp-file-name-equal-p
vec (car tramp-current-connection)))
(time-less-p
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory
2022-03-25 16:23 ` Michael Albinus
@ 2022-03-25 23:15 ` Dima Kogan
2022-03-26 10:57 ` Michael Albinus
0 siblings, 1 reply; 4+ messages in thread
From: Dima Kogan @ 2022-03-25 23:15 UTC (permalink / raw)
To: Michael Albinus; +Cc: 54542
Michael Albinus <michael.albinus@gmx.de> writes:
> We have already variable non-essential, which shall help for
> non-existing / broken connections. While I could reproduce your
> initial recipe locally, the attached patch cures it for me. Could you,
> please, test?
Hi Michael. Your patch fixes the issue. Thanks for looking into this!
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory
2022-03-25 23:15 ` Dima Kogan
@ 2022-03-26 10:57 ` Michael Albinus
0 siblings, 0 replies; 4+ messages in thread
From: Michael Albinus @ 2022-03-26 10:57 UTC (permalink / raw)
To: Dima Kogan; +Cc: 54542-done
Version: 29.1
Dima Kogan <dima@secretsauce.net> writes:
Hi Dima,
>> We have already variable non-essential, which shall help for
>> non-existing / broken connections. While I could reproduce your
>> initial recipe locally, the attached patch cures it for me. Could you,
>> please, test?
>
> Hi Michael. Your patch fixes the issue. Thanks for looking into this!
Thanks for the feedback. I've committed this to Emacs master, closing
the bug.
Best regards, Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-26 10:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-24 7:15 bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory Dima Kogan
2022-03-25 16:23 ` Michael Albinus
2022-03-25 23:15 ` Dima Kogan
2022-03-26 10:57 ` Michael Albinus
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).