Skip to content

pyo3: external header provider can hang during interpreter finalization #536

Backlog

Description

@cathleeny

The pyo3 binding's external header provider (Session(auth_type="external", header_provider=...), added in #527) runs the Python callable on a Tokio blocking-pool thread and attaches to the interpreter for each call (pyo3/src/auth.rs).

If an authenticated request runs while the Python interpreter is shutting down, for example a best-effort close spawned from Drop or a telemetry flush, that thread calls Python::attach during finalization. Depending on the Python version, the thread then hangs or is terminated, so interpreter exit can stall.

Suggested fix: before attaching, check whether the interpreter is finalizing (Py_IsFinalizing, or pyo3's equivalent). If it is, fail the request with Unauthenticated ("interpreter is shutting down") instead of calling the provider. Add a regression test that drops a session with an external provider during shutdown.

This only affects interpreter shutdown; normal requests are unaffected. Raised by the review bot on #527.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions