From: Austin Clements <aclements@csail.mit.edu>
To: David Bremner <david@tethera.net>
Cc: notmuch@notmuchmail.org, 843127@bugs.debian.org,
Paul Wise <pabs@debian.org>
Subject: Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?
Date: Sat, 12 Nov 2016 20:51:07 -0500 [thread overview]
Message-ID: <20161113015107.GC5670@csail.mit.edu> (raw)
In-Reply-To: <87a8df9pp2.fsf@tesseract.cs.unb.ca>
Quoth David Bremner on Nov 04 at 1:26 pm:
>
> Paul Wise wrote:
>
> > Last night I got this error from my `notmuch new --quiet` cron job. The
> > file that the error message complains about is now in the cur directory
> > of the maildir at the following path.
> >
> > /path/to/mail/cur/1478190211.H80553P18378.chianamo:2,
> >
> > I wonder if this some kind of race condition in `notmuch new` processing.
> > Perhaps it should be using inotify to find out about file movements?
> >
> > Unexpected error with file /path/to/mail/new/1478190211.H80553P18378.chianamo
> > add_file: Something went wrong trying to read or write a file
> > Error opening /path/to/mail/new/1478190211.H80553P18378.chianamo: No such file or directory
> > Note: A fatal error was encountered: Something went wrong trying to read or write a file
>
> I agree it looks like a race condition. inotify sounds a bit
> overcomplicated and perhaps non-portable? It should probably just
> tolerate disappearing files better, consider that a warning.
Inotify really *is* the solution. This is a symptom of a much bigger
problem: scandir makes no guarantees in the presence of concurrent
directory modification. If you delete or rename a file while notmuch
new is running, it may think *completely unrelated* files in the same
directory were also deleted. Even if scandir were atomic, if you move
a mail from one directory to another between notmuch scanning the
destination directory and notmuch scanning the source directory, it'll
think the mail has been deleted and potentially remove it from the DB.
The "recommended" solution is to scandir is to start an inotify watch
before the scan and redo (or update) the scan if there are any
changes. For notmuch, it would make sense to extend that to watching
all directories to make sure it can catch renames during the scan.
A possible alternative, though I haven't worked out the details, might
be to keep a close eye on the directory mtimes. Roughly, for each
directory, check the mtime before scanning, wait if necessary until
the mtime != the current time, do the scan and process the files
optimistically. Once all directories are processed, re-check all of
the mtimes and if any have changed, do something like starting over
but hopefully more intelligent.
next prev parent reply other threads:[~2016-11-13 2:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-04 12:46 [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`? David Bremner
2016-11-04 16:26 ` David Bremner
2016-11-13 1:51 ` Austin Clements [this message]
2016-11-14 18:44 ` J. Lewis Muir
2016-11-14 18:59 ` David Bremner
2016-11-04 18:47 ` Jani Nikula
2016-11-05 2:15 ` Paul Wise
2016-11-05 12:57 ` [PATCH] cli: consider files vanishing during notmuch new non-fatal Jani Nikula
2016-11-05 13:22 ` Paul Wise
2016-11-12 15:39 ` David Bremner
2016-11-12 16:04 ` Brian Sniffen
2016-11-12 16:10 ` David Bremner
2016-11-12 16:15 ` David Bremner
2016-11-12 21:08 ` Brian Sniffen
2016-11-12 21:36 ` David Bremner
2016-11-12 20:35 ` Jani Nikula
2016-11-16 11:43 ` David Bremner
2016-11-21 20:14 ` [PATCH v2] " Jani Nikula
2016-11-26 2:44 ` [PATCH] cli/new: document new exit code David Bremner
2016-11-26 9:17 ` Jani Nikula
2016-11-26 9:18 ` [PATCH] test: check the handling of files vanishing between scandir and indexing Jani Nikula
2016-11-27 9:59 ` [PATCH v2] " Jani Nikula
2016-11-29 2:16 ` David Bremner
2016-11-29 7:31 ` Tomi Ollila
2016-12-03 11:24 ` David Bremner
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://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161113015107.GC5670@csail.mit.edu \
--to=aclements@csail.mit.edu \
--cc=843127@bugs.debian.org \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
--cc=pabs@debian.org \
/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://yhetil.org/notmuch.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).