Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-14 Thread David Bremner
"J. Lewis Muir"  writes:

> On 11/12, Austin Clements wrote:
>> Quoth David Bremner on Nov 04 at  1:26 pm:
>> > 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.
>
> I don't see how inotify can be the solution unless the idea is to make
> Notmuch run on Linux only.  Inotify is a Linux kernel API.  Some other
> OSes have their own native file event notification facilities, but not
> all of them have it, and most (if not all) only support file event
> notifications for certain file systems and not for others (e.g., not for
> NFS).

Yeah, it's worth saying that, even if I think Austin knows. I was
thinking that an alternative approach might be to have either notmuch
new or notmuch insert take a file name on the command line, and let the
user call it via what ever kind of directory watcher utility works on
their system.

d
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-14 Thread J. Lewis Muir
On 11/12, Austin Clements wrote:
> Quoth David Bremner on Nov 04 at  1:26 pm:
> > 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.

I don't see how inotify can be the solution unless the idea is to make
Notmuch run on Linux only.  Inotify is a Linux kernel API.  Some other
OSes have their own native file event notification facilities, but not
all of them have it, and most (if not all) only support file event
notifications for certain file systems and not for others (e.g., not for
NFS).

Regards,

Lewis
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-12 Thread Austin Clements
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.

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-05 Thread Paul Wise
On Fri, 2016-11-04 at 20:47 +0200, Jani Nikula wrote:

> Do you have some other software modifying your mail store while
> you're running notmuch new?

The folder in question has my laptop's exim4 service writing to it when
my cron jobs generate email.

On Fri, 2016-11-04 at 13:26 -0300, David Bremner wrote:

> inotify sounds a bit overcomplicated and perhaps non-portable?

There are similar APIs on non-Linux OSes but there is indeed no common
API or library to abstract away this sort of feature AFAIK.

> It should probably just tolerate disappearing files better, consider
> that a warning.

That sounds like the correct solution indeed. Probably if the code
notices that a file disappeared, it should also rescan the nearby
folders to see if the file was moved instead of deleted.

> As a workaround, if you can replace background use of notmuch-new
> with notmuch-insert (and I understand this doesn't work for
> everyone), you will eliminate this kind of race condition.

Hmm, I don't think that will work for me.

-- 
bye,
pabs

https://wiki.debian.org/PaulWise


signature.asc
Description: This is a digitally signed message part
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-04 Thread Jani Nikula
On Fri, 04 Nov 2016, David Bremner  wrote:
> I wonder if this some kind of race condition in `notmuch new`
> processing.

Do you have some other software modifying your mail store while you're
running notmuch new?

BR,
Jani.
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-04 Thread David Bremner

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.

As a workaround, if you can replace background use of notmuch-new with
notmuch-insert (and I understand this doesn't work for everyone), you
will eliminate this kind of race condition.

d
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch