Skip to content

logging FileHandler.close should acquire its lock before closing stream #55653

Description

@AdamErnst
mannequin
BPO 11444
Nosy @vsajip

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/vsajip'
closed_at = <Date 2011-03-08.23:00:36.614>
created_at = <Date 2011-03-08.19:54:33.229>
labels = ['type-bug', 'library']
title = 'logging FileHandler.close should acquire its lock before closing stream'
updated_at = <Date 2011-03-11.18:49:08.616>
user = 'https://bugs.python.org/AdamErnst'

bugs.python.org fields:

activity = <Date 2011-03-11.18:49:08.616>
actor = 'python-dev'
assignee = 'vinay.sajip'
closed = True
closed_date = <Date 2011-03-08.23:00:36.614>
closer = 'vinay.sajip'
components = ['Library (Lib)']
creation = <Date 2011-03-08.19:54:33.229>
creator = 'Adam.Ernst'
dependencies = []
files = []
hgrepos = []
issue_num = 11444
keywords = []
message_count = 3.0
messages = ['130362', '130384', '130600']
nosy_count = 3.0
nosy_names = ['vinay.sajip', 'python-dev', 'Adam.Ernst']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue11444'
versions = ['Python 3.1', 'Python 2.7', 'Python 3.2', 'Python 3.3']

Activity

  1. AdamErnst commented on Mar 8, 2011

    AdamErnstmannequin
    MannequinAuthor

    This is my first report, apologies if I missed any tracker etiquette.

    The logging module registers shutdown() to run via atexit. shutdown() calls flush() and close() on each handler.

    However if a FileHandler is writing to a file while shutdown() is executing, an IOError will be raised as the file is being closed while written to. (This can happen if you use daemon threads, which can still be running while exiting.)

    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
        func(*targs, **kargs)
      File "/usr/local/lib/python2.7/logging/__init__.py", line 1616, in shutdown
        h.close()
      File "/usr/local/lib/python2.7/logging/__init__.py", line 898, in close
        self.stream.close()
    IOError: close() called during concurrent operation on the same file object.

    I'm not familiar with the internals of logging, but it seems that FileHandler should call self.acquire()/self.release() around its close and flush operations. Otherwise a daemon thread might be emitting a record while closing the handler.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Mar 8, 2011
  3. python-dev commented on Mar 8, 2011

    python-devmannequin
    Mannequin

    New changeset fc4d045e3170 by Vinay Sajip in branch '2.6':
    Issue bpo-11444: Lock handlers while flushing/closing during shutdown.
    http://hg.python.org/cpython/rev/fc4d045e3170

    New changeset c8b651b3a493 by Vinay Sajip in branch '2.7':
    Issue bpo-11444: Merge fix from 2.6.
    http://hg.python.org/cpython/rev/c8b651b3a493

    New changeset 16f8f359db9c by Vinay Sajip in branch '3.1':
    Issue bpo-11444: Lock handlers while flushing/closing during shutdown.
    http://hg.python.org/cpython/rev/16f8f359db9c

    New changeset 39469645857a by Vinay Sajip in branch '3.2':
    Issue bpo-11444: Merge fix from 3.1.
    http://hg.python.org/cpython/rev/39469645857a

    New changeset 1947cca7f583 by Vinay Sajip in branch 'default':
    Issue bpo-11444: Merge fix from 3.2.
    http://hg.python.org/cpython/rev/1947cca7f583

  4. self-assigned this
    on Mar 8, 2011
  5. python-dev commented on Mar 11, 2011

    python-devmannequin
    Mannequin

    New changeset d6626c9fc28d by Vinay Sajip in branch '2.6':
    Reverted bug fixes for bpo-11444 (fc4d045e3170) and bpo-11424 (b9d76846bb1c), which should not have been made in this branch.
    http://hg.python.org/cpython/rev/d6626c9fc28d

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions