question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

calling handler.close() from different thread causes deadlock when using AzureLogHandler

See original GitHub issue

Describe your environment. Python 3.8.13 on Linux, opencensus-ext-azure == 1.1.4, azureml-sdk[automl] ~= 1.42.0, azureml-mlflow==1.42.0, mlflow-skinny==1.26.0

Steps to reproduce. I can’t give an exact test code. The problem is related to #1112. We add an AzureLogHandler on the main thread. Then later we run automl Experiment in multiple threads.

The code in the thread at some point runs import mlflow, and the program stucks.

The import causes to run _configure_mlflow_loggers(root_module_name=__name__), which then runs the logging.config.dictConfig

This runs _clearExistingHandlers in logging.config, and inside of this, the shutdown function runs. The shutdown runs the following calls for all defined logging handlers:

   h.acquire()
   h.flush()
   h.close()

With previous versions, for example opencensus-ext-azure == 1.1.3 the program stuck at the h.flush() call. With the 1.1.4 version the h.flush() finishes, but then the run still stops when the self._worker.stop(timeout) is called inside the h.close().

What is the expected behavior? The import finishes successfully and the program continues

What is the actual behavior? The program stops in deadlock

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jorgenadercommented, Jun 22, 2022

@jorgenader Are you referring to this?

Yes, but more like adding default timeout instead.

0reactions
lzchencommented, Jun 21, 2022

@csadam Ideally, we would use the sentinel pattern as described here to avoid breaking changes, and then remove the custom atexit hook in place of logging shutdown.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deadlock with logging multiprocess/multithread python script
Once I set up the SLEEP_TIME to too "small" value, the LoggingThread threads somehow block the logging module. The script freeze on logging ......
Read more >
opencensus-python/__init__.py at master - GitHub
A stats collection and distributed tracing framework - opencensus-python/__init__.py at ... atexit first calls handler.close() and then logging.shutdown(),.
Read more >
Code that debugs itself: Fixing a deadlock with a watchdog ...
Our theory was that two threads were waiting on each other, as shown in the figure below. Thread A acquires lock then tries...
Read more >
Issue 25668: Deadlock in logging caused by a possible race ...
When an user, use logging, to try to display an object that uses some threading locks, there could be a race condition and...
Read more >
Avoiding Deadlock - Multithreaded Programming Guide
You can usually solve this type of problem by calling sched_yield() just before the call to reacquire the lock. The sched_yield() function allows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found