Skip to content

bpo-41503: Fix race between setTarget and flush in logging.handlers.MemoryHandler (GH-21765)#21765

Merged
vsajip merged 2 commits into
python:masterfrom
iritkatriel:logging_race
Aug 16, 2020
Merged

bpo-41503: Fix race between setTarget and flush in logging.handlers.MemoryHandler (GH-21765)#21765
vsajip merged 2 commits into
python:masterfrom
iritkatriel:logging_race

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Aug 7, 2020

Copy link
Copy Markdown
Member

…yHandler

The logging.handlers.MemoryHandler.setTarget() method does not acquire the lock, so it can change the target while flush is processing the buffer.

https://bugs.python.org/issue41503

@vsajip vsajip added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 15, 2020
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vsajip for commit e3884b0 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 15, 2020

@vsajip vsajip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the test fail if you leave setTarget() unchanged?

@iritkatriel

iritkatriel commented Aug 15, 2020

Copy link
Copy Markdown
Member Author

Yes, are you not seeing that?

======================================================================
ERROR: test_race_between_set_target_and_flush (test.test_logging.MemoryHandlerTest)

Traceback (most recent call last):
File "C:\Users\User\src\cpython\lib\test\test_logging.py", line 1201, in test_race_between_set_target_and_flush
self.mem_logger.warning("flushed")
File "C:\Users\User\src\cpython\lib\logging_init_.py", line 1390, in warning
self.log(WARNING, msg, args, **kwargs)
File "C:\Users\User\src\cpython\lib\logging_init
.py", line 1514, in log
self.handle(record)
File "C:\Users\User\src\cpython\lib\logging_init
.py", line 1524, in handle
self.callHandlers(record)
File "C:\Users\User\src\cpython\lib\logging_init_.py", line 1586, in callHandlers
hdlr.handle(record)
File "C:\Users\User\src\cpython\lib\logging_init_.py", line 894, in handle
self.emit(record)
File "C:\Users\User\src\cpython\lib\logging\handlers.py", line 1235, in emit
self.flush()
File "C:\Users\User\src\cpython\lib\logging\handlers.py", line 1311, in flush
self.target.handle(record)
AttributeError: 'NoneType' object has no attribute 'handle'

@vsajip

vsajip commented Aug 16, 2020

Copy link
Copy Markdown
Member

Yes, are you not seeing that?

I didn't test it myself - just wanted to confirm that was the case. Thanks! I'll mark for automerge and approve as soon as the remaining buildbots are done.

@vsajip vsajip changed the title bpo-41503: Race between setTarget and flush in logging.handlers.Memor… bpo-41503: Fix race between setTarget and flush in logging.handlers.MemoryHandler (GH-21765) Aug 16, 2020
@vsajip vsajip merged commit 2353d77 into python:master Aug 16, 2020
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @iritkatriel for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @iritkatriel for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 16, 2020
…emoryHandler (pythonGH-21765)

(cherry picked from commit 2353d77)

Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
@bedevere-bot

Copy link
Copy Markdown

GH-21897 is a backport of this pull request to the 3.9 branch.

@bedevere-bot

Copy link
Copy Markdown

GH-21898 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 16, 2020
…emoryHandler (pythonGH-21765)

(cherry picked from commit 2353d77)

Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
miss-islington added a commit that referenced this pull request Aug 16, 2020
…lers.MemoryHandler (GH-21765) (GH-21897)

(cherry picked from commit 2353d77)


Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>

Automerge-Triggered-By: @vsajip
miss-islington added a commit that referenced this pull request Aug 16, 2020
…lers.MemoryHandler (GH-21765) (GH-21898)

(cherry picked from commit 2353d77)


Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>

Automerge-Triggered-By: @vsajip
@iritkatriel iritkatriel deleted the logging_race branch August 16, 2020 17:53
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
@iritkatriel iritkatriel added the type-bug An unexpected behavior, bug, or error label Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants