#26298·mlflow

[BUG] mlflow.autolog() can deadlock against mlflow's own background threads via CPython's per-module import lock (non-Databricks)

Author: habibaikram1Created Sep 30, 2026Updated Sep 30, 2026
Labelsbugarea/tracking

[!WARNING] Before submitting a PR, please make sure that:

  • A maintainer has triaged this issue and applied the ready label
  • This issue has no assignee
  • No duplicate PR exists

PRs not meeting these requirements may be automatically closed.

Issues Policy acknowledgement

  • I have read and agree to submit bug reports in accordance with the issues policy

Where did you encounter this bug?

Other

MLflow version

  • Client: 3.15.x-3.16.1
  • Tracking server: self-hosted OSS tracking server (not Databricks-managed)

System information

  • OS Platform and Distribution: Linux containers (Kubernetes)
  • Python version: 3.12
  • Orchestration: Kubeflow Pipelines (KFP v2) components, orchestrated via Argo Workflows. A hang manifests as the Argo Workflow node staying stuck in RUNNING forever with no further pod output.

Describe the problem

We've hit two independently confirmed, non-deterministic hangs in mlflow.autolog(), both traced via faulthandler thread dumps on live hung pods (no ptrace available in our environment) to the same underlying mechanism: CPython's per-module import lock deadlocking between the main thread and one of mlflow's own background threads. The same commit/job can complete cleanly on one run and hang indefinitely on the next.

Hang #1 (autolog() called after start_run()): hung permanently right after the log line "Autologging successfully enabled for boto3." mlflow.start_run() spawns several background threads (system-metrics monitor, telemetry consumer, async logging queue) that do their own lazy imports concurrently with autolog()'s framework auto-detection sweep running on the main thread. The interleaving deadlocks on CPython's import lock. Reordering our code to call autolog() before start_run() (so the sweep completes before those threads exist) reduced the frequency of this occurrence, but as noted below, did not eliminate it.

Hang #2 (same version range, after applying the above reordering): still hung intermittently -- this time right after "Autologging successfully enabled for keras." (sklearn is next alphabetically in the sweep; TensorFlow is never even reached). Main thread stack: mlflow.autolog() -> mlflow.sklearn.autolog() -> _gen_estimators_to_patch() -> sklearn.utils.discovery.all_estimators() -> pkgutil.walk_packages(), blocked acquiring CPython's per-module import lock. Concurrently, MLflowTelemetryConsumer-0 (started via set_telemetry_client() at import mlflow time, independent of start_run()) was doing a lazy import through mlflow's own import-hook machinery.

Both hangs are the same class of bug: two threads racing to import modules in different orders, each holding a different module's import lock while waiting on the other's (bpo-10923, https://bugs.python.org/issue10923 -- a long-standing CPython limitation, not specific to 3.12). What's specific to mlflow is that autolog()'s own import-heavy sweep runs on the main thread while mlflow's own machinery (start_run()'s background threads, and independently the telemetry consumer) is doing concurrent imports -- so mlflow is racing against itself.

We noticed #24841 (https://github.com/mlflow/mlflow/pull/24841) fixes a related deadlock by pre-importing databricks.sdk before the telemetry consumer needs it, but that fix is scoped to _forward_to_databricks() and gated behind _MLFLOW_TELEMETRY_PRE_WARM_DATABRICKS_SDK (opt-in, off by default) -- it doesn't help non-Databricks tracking backends like ours, and it wouldn't cover Hang #1 (which isn't telemetry-specific at all).

Setting MLFLOW_DISABLE_TELEMETRY=true did not reliably fix this for us either -- we shipped it and still saw the job hang in production. We eventually traced that specific failure to a bug in our own SDK (an unrelated import ordering issue silently letting mlflow get imported, and its telemetry client constructed, before our code set the env var), so we can't yet conclusively say whether telemetry-disable is sufficient on mlflow's side once correctly applied before import mlflow. The only thing that has reliably unblocked us so far is disabling autolog() entirely, which obviously isn't a real fix.

Questions for maintainers:

  1. Would you consider applying the same "pre-import before the background thread needs it" pattern generally (not gated to Databricks), for both the telemetry consumer and start_run()'s other background threads?
  2. Is MLFLOW_DISABLE_TELEMETRY actually expected to prevent the telemetry consumer thread from ever starting if set before import mlflow, in every code path (not just _forward_to_databricks)? We want to confirm our mental model before ruling it out as insufficient.

Tracking information

bash
Tracking URI: <non-Databricks self-hosted MLflow tracking server>

Code to reproduce issue

import mlflow

mlflow.set_tracking_uri("<your non-Databricks tracking server URI>")
with mlflow.start_run():
    mlflow.autolog()  # races start_run()'s background threads' own lazy imports;
                       # intermittently deadlocks here or a few lines later
print("reached")  # never printed on a hung run

Stack trace

Paraphrased from faulthandler dumps on hung production pods (not a copy-pasted
traceback -- happy to attach raw dumps if useful):

Hang #1:
  MainThread: blocked inside mlflow.boto3.autolog()'s import sweep
  <start_run()-spawned background thread>: blocked inside its own lazy import

Hang #2:
  MainThread:
    importlib._bootstrap._ModuleLock.acquire()
    <- sklearn.utils.discovery.all_estimators() via pkgutil.walk_packages()
    <- mlflow.sklearn._gen_estimators_to_patch()
    <- mlflow.sklearn.autolog()
    <- mlflow.autolog()

  MLflowTelemetryConsumer-0:
    importlib._bootstrap._ModuleLock.acquire()  (different module than MainThread)

Other info / logs

Current workaround: call autolog() before start_run(), and set MLFLOW_DISABLE_TELEMETRY=true before any `import mlflow` in the process. Neither alone was sufficient in our testing; we're not fully confident even the combination is sufficient given the ordering bug described above.

Update: we saw a fresh occurrence of Hang #1 after filing this issue, with the exact same last log line ("Autologging successfully enabled for boto3.") despite the autolog()-before-start_run() reordering already being deployed and verified in place at the time. So the reordering reduces but does not eliminate this hang.

What component(s) does this bug affect?

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow model serving, deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/prompt: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting
  • area/docs: MLflow documentation pages