This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Mailbox will not lock properly after flush()
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, deuxpi
Priority: normal Keywords: patch

Created on 2006-10-11 19:56 by deuxpi, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mailbox-relock.patch deuxpi, 2006-10-11 19:56 Patch for Lib/mailbox.py
Messages (2)
msg51229 - (view) Author: Philippe Gauthier (deuxpi) Date: 2006-10-11 19:56
The _singlefileMailbox class will try to lock the wrong
file object after a flush(), resulting into an
operation on a closed file object. 

The following code should illustrate the bug. See also
the attached patch.

>>> import mailbox
>>>
>>> box = mailbox.mbox('mbox')
>>> msg = "Subject: sub\n\nbody\n"
>>> box.add(msg)
0
>>> box.flush()
>>> box.close()
>>>
>>> box = mailbox.mbox('mbox')
>>> box.lock()
>>> box.add(msg)
1
>>> box.flush()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/mailbox.py", line 581, in flush
    _lock_file(new_file, dotlock=False)
  File "/usr/lib/python2.5/mailbox.py", line 1847, in
_lock_file
    fcntl.lockf(f, fcntl.LOCK_UN)
ValueError: I/O operation on closed file
msg51230 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-10-27 16:58
Logged In: YES 
user_id=11375

Good catch!  I think your analysis and patch are correct,
and have applied the changes to the trunk (rev. 52478) and
25-maint (rev. 52479).  Thanks!
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44114
2006-10-11 19:56:31deuxpicreate