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: logging.RotatingFileHandler not robust enough
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: eric.araujo, georg.brandl, kalt, vinay.sajip
Priority: normal Keywords: patch

Created on 2011-01-19 17:11 by kalt, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
logging.diff kalt, 2011-01-19 17:11
Messages (5)
msg126541 - (view) Author: Christophe Kalt (kalt) Date: 2011-01-19 17:11
logging.RotatingFileHandler.doRollover() can fail leaving the handler with a closed filehandle, causing all subsequent logging attempts to fail:

>>> import logging
>>> import logging.handlers
>>> logging.getLogger().addHandler(logging.handlers.RotatingFileHandler('testlog', None, 10, 5))
>>> logging.getLogger().setLevel(logging.INFO)
>>> logging.info('qwertyuiop')
>>> os.system('ls -l testlog*')
-rw-r--r-- 1 - - 11 Jan 19 10:02 testlog
-rw-r--r-- 1 - -  0 Jan 19 10:02 testlog.1
0
>>> os.remove('testlog')
>>> logging.info('qwertyuiop')
Traceback (most recent call last):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 72, in emit
    self.doRollover()
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 129, in doRollover
    os.rename(self.baseFilename, dfn)
OSError: [Errno 2] No such file or directory
>>> logging.info('qwertyuiop')
Traceback (most recent call last):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 145, in shouldRollover
    self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file
>>> logging.info('qwertyuiop')
Traceback (most recent call last):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 145, in shouldRollover
    self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file

Fix seems trivial enough, attaching.  This is against 2.6.5, browsing subversion online seems to indicate it is needed on the trunk as well, although it won't apply cleanly.
msg126796 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-01-21 23:38
Fix checked into py3k, release27-maint, release31-maint (r88139). The 2.6 branch is closed for changes other than security fixes.
msg126853 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-01-22 19:04
Is it okay that there is no test?
msg126854 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-22 19:07
You could have said that the py3k branch is closed for changes without tests or review...
msg126888 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-01-23 11:53
<facepalm>Sorry, Georg! I think I've been working too hard, this completely passed me by. Should have left py3k till later, as it's not that urgent.</facepalm>
History
Date User Action Args
2022-04-11 14:57:11adminsetgithub: 55158
2011-01-23 11:53:10vinay.sajipsetnosy: georg.brandl, vinay.sajip, kalt, eric.araujo
messages: + msg126888
2011-01-22 19:07:55georg.brandlsetnosy: + georg.brandl
messages: + msg126854
2011-01-22 19:04:26eric.araujosetversions: + Python 3.2, - Python 2.6
nosy: + eric.araujo

messages: + msg126853

stage: resolved
2011-01-21 23:38:01vinay.sajipsetstatus: open -> closed

messages: + msg126796
resolution: fixed
assignee: vinay.sajip
2011-01-21 21:48:44r.david.murraysetnosy: + vinay.sajip
2011-01-19 17:11:06kaltcreate