Skip to content

Fix session use-after-free when UserLoggingFunction is used#28314

Open
tianleiwu wants to merge 1 commit intomainfrom
tlwu/20260501/logger_crash_fix_follow_up
Open

Fix session use-after-free when UserLoggingFunction is used#28314
tianleiwu wants to merge 1 commit intomainfrom
tlwu/20260501/logger_crash_fix_follow_up

Conversation

@tianleiwu
Copy link
Copy Markdown
Contributor

Description

Follow-up to #28274. Addresses reviewer feedback by also moving user_logging_manager_ (and its raw pointer alias logging_manager_) before owned_session_logger_ and execution_providers_ in InferenceSession's member declaration order.

When SessionOptions::user_logging_function is set, the session creates a per-session user_logging_manager_ and the session logger is created from it. Previously, user_logging_manager_ was declared after execution_providers_, causing the logging manager to be destroyed before EPs during session teardown — a use-after-free if any EP logs in its destructor.

Changes

  • inference_session.h: Move logging_manager_ and user_logging_manager_ declarations to before owned_session_logger_ and execution_providers_, ensuring correct destruction order.
  • inference_session_test.cc: Add SessionLoggerOutlivesEPsWithUserLoggingFunction regression test that validates the user-logging-function path.

Testing

All three SessionLoggerOutlivesEPs* tests pass locally:

[  PASSED  ] 3 tests.
  - SessionLoggerOutlivesEPsOnDestruction (16 ms)
  - SessionLoggerOutlivesEPsWithMultipleEPs (12 ms)
  - SessionLoggerOutlivesEPsWithUserLoggingFunction (1 ms)

Fixes #28234

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.

Session logger destroyed before EP teardown callbacks — use-after-free under VERBOSE logging

1 participant