Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueueHandler logs stack_info twice #90911

Closed
emontnemery mannequin opened this issue Feb 15, 2022 · 2 comments
Closed

QueueHandler logs stack_info twice #90911

emontnemery mannequin opened this issue Feb 15, 2022 · 2 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@emontnemery
Copy link
Mannequin

emontnemery mannequin commented Feb 15, 2022

BPO 46755
Nosy @vsajip, @emontnemery, @emontnemery
PRs
  • bpo-46755: Don't log stack info twice in QueueHandler #31355
  • 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 = None
    closed_at = None
    created_at = <Date 2022-02-15.08:36:55.743>
    labels = ['type-bug', 'library', '3.9']
    title = 'QueueHandler logs stack_info twice'
    updated_at = <Date 2022-02-17.00:10:50.289>
    user = 'https://github.com/emontnemery'

    bugs.python.org fields:

    activity = <Date 2022-02-17.00:10:50.289>
    actor = 'ned.deily'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-02-15.08:36:55.743>
    creator = 'erik.montnemery'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46755
    keywords = ['patch']
    message_count = 1.0
    messages = ['413278']
    nosy_count = 3.0
    nosy_names = ['vinay.sajip', 'emontnemery', 'erik.montnemery']
    pr_nums = ['31355']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46755'
    versions = ['Python 3.9']

    @emontnemery
    Copy link
    Mannequin Author

    emontnemery mannequin commented Feb 15, 2022

    logging.handlers.QueueHandler logs stack twice when stack_info=True:

    >>> import logging
    >>> from logging.handlers import QueueHandler, QueueListener
    >>> from queue import Queue
    >>> q = Queue()
    >>> logging.getLogger().addHandler(QueueHandler(q))
    >>> listener = QueueListener(q, logging.StreamHandler())
    >>> listener.start()
    >>> _LOGGER.error("Hello", stack_info=True)
    Hello
    Stack (most recent call last):
      File "<stdin>", line 1, in <module>
    Stack (most recent call last):
      File "<stdin>", line 1, in <module>

    Reproduced on CPython 3.9.9, but the code is unchanged in 3.10 and 3.11, so the issue should exist there too.

    Patching QueueHandler.prepare() to set stack_info to None seems to fix this:

    diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
    index d42c48de5f..7cd5646d85 100644
    --- a/Lib/logging/handlers.py
    +++ b/Lib/logging/handlers.py
    @@ -1452,6 +1452,7 @@ def prepare(self, record):
             record.args = None
             record.exc_info = None
             record.exc_text = None
    +        record.stack_info = None
             return record
         def emit(self, record):

    Related issue: bpo-34334, with patch #9537

    @emontnemery emontnemery mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 15, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @vsajip
    Copy link
    Member

    vsajip commented Jul 5, 2022

    The PR was merged and backported to 3.10 and 3.11.

    @vsajip vsajip closed this as completed Jul 5, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    Development

    No branches or pull requests

    1 participant