unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Jacobowitz <daniel.jacobowitz@gmail.com>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 66381@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>
Subject: bug#66381: 29.1; Auto-revert not polling files when notifications are enabled
Date: Sat, 7 Oct 2023 12:14:52 -0400	[thread overview]
Message-ID: <CAN9gPaHLWig0OJxgZUpYx__aNOT=Kw3A5hzAT4j-60zngfoUPg@mail.gmail.com> (raw)
In-Reply-To: <87bkdaihuo.fsf@gmx.de>

emacs -Q --eval '(setq auto-revert-debug t file-notify-debug t)'
--eval '(global-auto-revert-mode t)' file.txt

Modify the file outside of Emacs:

file-notify-handle-event (file-notify ((1 . 0) (modify) "file.txt" 0)
file-notify--callback-inotify)
file-notify-callback (1 . 0) changed "/path/to/file.txt" nil
#s(file-notify--watch "/path/to" "file.txt"
auto-revert-notify-handler) "/path/to/file.txt" "/path/to/google3"
auto-revert-notify-handler ((1 . 0) changed "/path/to/file.txt")
Reverting buffer ‘file.txt’

Restart the network filesystem (sudo systemctl restart netfs). Modify
the file outside of Emacs again.

Nothing new in *Messages* for either the restart or the modification.

Hit a key in the file buffer:

file.txt changed on disk; really edit the buffer? (y, n, r or C-h)

Same story with inotify; there's no event when the filesystem
restarts. I'm not explicitly unmounting it, systemd kills and restarts
the job providing the fuse filesystem.

The path does not match auto-revert-notify-exclude-dir-regexp.

If supporting this is of general interest, I'd do it by (A)
re-enabling polling even when using notification; (B) removing and
re-adding the watch when polling reports changes that we weren't
notified about. If it's not of general interest, the best alternative
would be removing the bit of documentation that says "By default, Auto
Revert mode will poll files for changes periodically even when file
notifications are used."

For anyone with a similar problem, since the filesystem restarts are
typically overnight as part of system updates, I went with a simple
workaround:

(run-with-timer 1800 1800 (lambda () (progn
                                       (global-auto-revert-mode 'toggle)
                                       (global-auto-revert-mode 'toggle))))

On Sat, Oct 7, 2023 at 11:15 AM Michael Albinus <michael.albinus@gmx.de> wrote:
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> Hi Eli,
>
> >> I use a network filesystem which sometimes has to restart, e.g.  for
> >> updates or when credentials expire. Normally, file notifications work
> >> fine on this filesystem, but after a restart the old notifications will
> >> never fire. Documentation says "By default, Auto Revert mode will poll
> >> files for changes periodically even when file notifications are used." -
> >> experimentally the file is never polled.
> >>
> >> Ideally the notification would be recreated, but falling back to
> >> polling would be
> >> an improvement.
> >
> > Michael, can we reliably know when the watch handles are stale?  If
> > not, then users of such "restarting" network filesystems will need to
> > disable auto-revert-use-notify.
>
> We have `file-notify-valid-p'. It calls the backend specific funtion,
> for example `inotify-valid-p' in the case of GNU/Linux using
> inotify. The OP didn't tell us which backend he's using, so let's assume
> inotify ATM.
>
> This backend specific check does not ask the operating system, it checks
> only some internal data structures. This isn't a robust check for a
> stale watch handle.
>
> However, inotify sends also an internal event IN_IGNORED, which is
> raised according to inotify(7)
>
> --8<---------------cut here---------------start------------->8---
>            IN_IGNORED
>                   Watch  was removed explicitly (inotify_rm_watch(2)) or auto‐
>                   matically (file was deleted, or filesystem  was  unmounted).
>                   See also BUGS.
> --8<---------------cut here---------------end--------------->8---
>
> filenotify.el translates this to the Emacs file-notify event `stopped',
> and if this event arrives, the respective data structures are
> updated. In case of a network filesystem unmount, everything shall work.
>
> A recreation of file notification after a remount is not supported. This
> would be a new feature.
>
> However, the situation is more complex I fear. If I understand the OP
> message correctly, file notification is used for auto-revert-mode. There
> is the user option `auto-revert-notify-exclude-dir-regexp'. If a
> directory located on a file name matching this regexp, file notification
> is discarded. File names like  "/mnt", "/net/", or "/tmp_mnt/" match. So
> in order to use file notification with auto-revert-mode on such a
> location, this user option must be adapted.
>
> I haven't tested the combination of watching a mounted file system, and
> unmounting them, in autorevert.el. According to
> `auto-revert-notify-handler', the file-notify event `stopped' is
> handled, and auto-revert-mode continues with polling. I would test this
> once I see a clear recipe (starting with
>
> --8<---------------cut here---------------start------------->8---
> emacs -Q --eval '(setq auto-revert-debug t file-notify-debug t)'
> --8<---------------cut here---------------end--------------->8---
>
> and telling all steps how to enable auto-revert-mode and how to unmount
> the filesystem and what happens afterwards. The two debug options show
> us the story in the *Messages* buffer.
>
> Best regards, Michael.



-- 
Thanks,
Daniel





  reply	other threads:[~2023-10-07 16:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06 17:13 bug#66381: 29.1; Auto-revert not polling files when notifications are enabled Daniel Jacobowitz
2023-10-07  6:17 ` Eli Zaretskii
2023-10-07 15:15   ` Michael Albinus
2023-10-07 16:14     ` Daniel Jacobowitz [this message]
2023-10-07 17:02       ` Michael Albinus
     [not found]         ` <CAN9gPaEi7yPgC4cA9fR-TtSmsVg6CoTOZ=bbZFa1gjQA_B1vGA@mail.gmail.com>
2023-10-07 17:59           ` Michael Albinus
2023-10-07 18:14             ` Daniel Jacobowitz
2023-10-07 18:28               ` Eli Zaretskii
2023-10-07 18:41                 ` Daniel Jacobowitz
2023-10-07 18:48                   ` Daniel Jacobowitz
2023-10-07 19:00                   ` Eli Zaretskii
2023-10-08  8:24                     ` Michael Albinus
2023-10-08 12:38                       ` Michael Albinus
2023-10-09 18:17                         ` Daniel Jacobowitz
2023-10-10 18:03                           ` Michael Albinus
2023-10-13 12:05                             ` Eli Zaretskii
2023-10-15 13:58                               ` Michael Albinus
2023-10-16 12:38                                 ` Eli Zaretskii
2023-10-16 14:29                                   ` Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN9gPaHLWig0OJxgZUpYx__aNOT=Kw3A5hzAT4j-60zngfoUPg@mail.gmail.com' \
    --to=daniel.jacobowitz@gmail.com \
    --cc=66381@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=michael.albinus@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).