Skip to content

Fix issue where deadlock can occur over logging._lock #4636

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DylanRussell
Copy link
Contributor

Description

We (google) saw a deadlock occur when logging.config.dictConfig is called after the OTEL LoggingHandler is attached to the root logger.

This happened b/c dictConfig acquires logging._lock and then clearsHandlers which then calls shutdown on the OTEL LoggingHandler, which calls flush.

flush triggered an export call to our exporter. Deep inside our exporter we spin up a new thread to handle auth, and that thread also tried to acquire logging._lock resulting in a deadlock..

To fix this I updated LoggingHandler.flush to execute force_flush in a separate thread, and not to block/wait before returning.. This should be reasonable because we don't return the result of the force flush anyway, so why block there.

This seems to reliably fix the deadlock, but I think it's technically possible for this new thread to spin up and reach the lock before logging.config.dictConfig releases it's lock..

Another simple fix is to set flushOnClose to true, so that the OTEL LogHandler.flush is not called during shutdown. This seems fine to me as well because we call shutdown on exit anyway. Either of these solutions seem fine.

Also considered making our exporter async, but we don't have support for async exporter's in this repo yet.

Type of change

  • [x ] Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I've added a unit test to show how the deadlock happens.. I don't think that test should actually be submitted because of the chance a deadlock can occur and lock up the test suite..

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • [x ] No.

Checklist:

  • [ x] Followed the style guidelines of this project
  • Changelogs have been updated
  • [ x] Unit tests have been added
  • [x ] Documentation has been updated

@DylanRussell DylanRussell requested a review from a team as a code owner June 13, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant