Skip to content

Commit

Permalink
Fix crash when running ORT under low integrity process like Edge wher…
Browse files Browse the repository at this point in the history
…e ETW registration can fail (microsoft#22699)

### Description
Make ETW provider registration non-fatal and not throw an exception

Needs to work under build with exceptions enabled & --disable_exceptions

### Motivation and Context
ORT should not crash

Addresses microsoft#22475. Private tested by filer of that issue
  • Loading branch information
ivberg authored and ankitm3k committed Dec 11, 2024
1 parent c7ac244 commit 85bf160
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions onnxruntime/core/platform/windows/logging/etw_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ void EtwRegistrationManager::LazyInitialize() {
initialization_status_ = InitializationStatus::Initializing;
etw_status_ = ::TraceLoggingRegisterEx(etw_provider_handle, ORT_TL_EtwEnableCallback, nullptr);
if (FAILED(etw_status_)) {
// Registration can fail when running under Low Integrity process, and should be non-fatal
initialization_status_ = InitializationStatus::Failed;
ORT_THROW("ETW registration failed. Logging will be broken: " + std::to_string(etw_status_));
LOGS_DEFAULT(WARNING) << "Error in ETW registration: " << std::to_string(etw_status_);
}
initialization_status_ = InitializationStatus::Initialized;
}
Expand All @@ -176,7 +177,9 @@ void EtwRegistrationManager::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled,

std::lock_guard<std::mutex> lock(callbacks_mutex_);
for (const auto& callback : callbacks_) {
(*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext);
if (callback != nullptr) {
(*callback)(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions onnxruntime/core/session/inference_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,12 @@ InferenceSession::~InferenceSession() {
// Unregister the session and ETW callbacks
#ifdef _WIN32
std::lock_guard<std::mutex> lock(active_sessions_mutex_);
WindowsTelemetry::UnregisterInternalCallback(callback_ML_ORT_provider_);
logging::EtwRegistrationManager::Instance().UnregisterInternalCallback(callback_ETWSink_provider_);
if (callback_ML_ORT_provider_ != nullptr) {
WindowsTelemetry::UnregisterInternalCallback(callback_ML_ORT_provider_);
}
if (callback_ETWSink_provider_ != nullptr) {
logging::EtwRegistrationManager::Instance().UnregisterInternalCallback(callback_ETWSink_provider_);
}
#endif
active_sessions_.erase(session_id_);

Expand Down

0 comments on commit 85bf160

Please sign in to comment.