Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7360] [mailbox] race: mbox may lose data with concurrent access

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 19, 2009, 8:20 AM

Post #1 of 6 (277 views)
Permalink
[issue7360] [mailbox] race: mbox may lose data with concurrent access

New submission from Matthias Klose <doko [at] debian>:

[forwarded from http://bugs.debian.org/451733]

the mailbox._singlefileMailbox class is not safe with concurrent access,
because mailbox._singlefileMailbox.flush() replaces the underlying file
with a new copy by constructing a temporary file and then renaming it.
This breaks all other class instances which have this mailbox open. I'm
attaching a script demonstrating the problem.

I think it's a bad idea to use rename(2) here; overwriting the file
content would fix the race condition, and #451274 too[1].

----------
components: Library (Lib)
messages: 95487
nosy: doko
severity: normal
status: open
title: [mailbox] race: mbox may lose data with concurrent access
versions: Python 2.6

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 19, 2009, 8:20 AM

Post #2 of 6 (259 views)
Permalink
[issue7360] [mailbox] race: mbox may lose data with concurrent access [In reply to]

Changes by Matthias Klose <doko [at] debian>:


Added file: http://bugs.python.org/file15364/mailbox-race.py

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 19, 2009, 8:52 AM

Post #3 of 6 (259 views)
Permalink
[issue7360] [mailbox] race: mbox may lose data with concurrent access [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

> the mailbox._singlefileMailbox class is not safe with concurrent access,
> because mailbox._singlefileMailbox.flush() replaces the underlying file
> with a new copy by constructing a temporary file and then renaming it.
> This breaks all other class instances which have this mailbox open.

I don't think this class aims at being safe against concurrent access,
so having it fail loudly is a good thing.
Besides, the proposed cure (overwriting instead of renaming) looks worse
than the illness. The virtue of renaming is that it is atomic (on POSIX
systems at least), so you can't end up with a half-written mailbox if
there's a crash or an IO problem in the middle.

----------
nosy: +pitrou

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 19, 2009, 9:06 AM

Post #4 of 6 (258 views)
Permalink
[issue7360] [mailbox] race: mbox may lose data with concurrent access [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

Oops, sorry:
> I don't think this class aims at being safe against concurrent access,
> so having it fail loudly is a good thing.

I now understand that the problem is that it doesn't fail loudly. That's
what I get for replying too quickly.
Still, I don't think the suggested fix is ok. Perhaps we should simply
state in the documentation that flush() discards the old file, so that
other processes accessing it may get a surprise.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 19, 2009, 9:18 AM

Post #5 of 6 (258 views)
Permalink
[issue7360] [mailbox] race: mbox may lose data with concurrent access [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

Actually, the doc is quite clear about it:

« Be very cautious when modifying mailboxes that might be simultaneously
changed by some other process. The safest mailbox format to use for such
tasks is Maildir; try to avoid using single-file formats such as mbox
for concurrent writing. »

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 19, 2009, 5:34 PM

Post #6 of 6 (249 views)
Permalink
[issue7360] [mailbox] race: mbox may lose data with concurrent access [In reply to]

Changes by Antoine Pitrou <pitrou [at] free>:


----------
nosy: +akuchling

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.