Skip to content

gh-79366: Fix a race condition when removing a logging handler#154528

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:fix-logger-handler-race
Open

gh-79366: Fix a race condition when removing a logging handler#154528
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:fix-logger-handler-race

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

removeHandler() removed the handler from the list in place. If a handler was removed while callHandlers() was iterating over the same list, whether from another thread or from within an emit() call, the following handlers of the same logger could be skipped, so records were not passed to them.

removeHandler() now replaces the list with a copy instead of mutating it in place, so callHandlers() always iterates over a consistent list without needing to acquire the lock. Adding a handler already appends to the end, so it cannot cause a handler to be skipped and is left unchanged.

🤖 Generated with Claude Code

removeHandler() mutated the handler list in place, so if a handler was
removed while callHandlers() was iterating the same list, the following
handlers could be skipped.  Replace the list instead of mutating it.

Co-Authored-By: Ben Spiller <11992588+ben-spiller@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant